Qore Programming Language  0.8.11.1
QoreString.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreString.h
4 
5  QoreString Class Definition
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2014 David Nichols
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_QORESTRING_H
35 
36 #define _QORE_QORESTRING_H
37 
38 #include <stdarg.h>
39 
40 #include <string>
41 
42 class DateTime;
43 class BinaryNode;
44 
46 
50 class QoreString {
51  friend struct qore_string_private;
52 protected:
54  struct qore_string_private* priv;
55 
56  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, QoreString* extract = 0);
57  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char* str, qore_size_t str_len, QoreString* extract = 0);
58  DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink* xsink, QoreString* extract = 0);
59  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink, QoreString* extract = 0);
60  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString* str, ExceptionSink* xsink, QoreString* extract = 0);
61  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset) const;
62  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset, qore_offset_t length) const;
63  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, ExceptionSink* xsink) const;
64  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
65 
66  // writes a new QoreString with the characters reversed of the "this" QoreString
67  // assumes the encoding is the same and the length is 0
68  DLLLOCAL void concat_reverse(QoreString* targ) const;
69 
70  DLLLOCAL int snprintf(size_t size, const char* fmt, ...);
71  DLLLOCAL int vsnprintf(size_t size, const char* fmt, va_list args);
72  DLLLOCAL static int convert_encoding_intern(const char* src, qore_size_t src_len, const QoreEncoding* from, QoreString& targ, const QoreEncoding* to, ExceptionSink* xsink);
73 
74 public:
76  DLLEXPORT QoreString();
77 
79  DLLEXPORT QoreString(bool b);
80 
82  DLLEXPORT QoreString(const char* str);
83 
85  DLLEXPORT QoreString(const char* str, const QoreEncoding* new_qorecharset);
86 
88  DLLEXPORT QoreString(const QoreEncoding* new_qorecharset);
89 
91  DLLEXPORT QoreString(const char* str, qore_size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
92 
94  DLLEXPORT QoreString(const std::string& str, const QoreEncoding* new_encoding = QCS_DEFAULT);
95 
97  DLLEXPORT QoreString(char c);
98 
100  DLLEXPORT QoreString(const QoreString& str);
101 
103  DLLEXPORT QoreString(const QoreString* str);
104 
106  DLLEXPORT QoreString(const QoreString* str, qore_size_t len);
107 
109  DLLEXPORT QoreString(int64 i);
110 
112  DLLEXPORT QoreString(double f);
113 
115  DLLEXPORT QoreString(const DateTime* date);
116 
118  DLLEXPORT QoreString(const BinaryNode* bin);
119 
121  DLLEXPORT QoreString(const BinaryNode* bin, qore_size_t maxlinelen);
122 
124  DLLEXPORT QoreString(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
125 
127  DLLEXPORT ~QoreString();
128 
130 
132  DLLEXPORT qore_size_t length() const;
133 
135  DLLEXPORT void set(const char* str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
136 
138  DLLEXPORT void set(const std::string& str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
139 
141  DLLEXPORT void set(const QoreString* str);
142 
144  DLLEXPORT void set(const QoreString& str);
145 
147  DLLEXPORT void setEncoding(const QoreEncoding* new_encoding);
148 
150  DLLEXPORT void concatAndHTMLEncode(const char* str);
151 
153  DLLEXPORT void concatAndHTMLDecode(const QoreString* str);
154 
156  DLLEXPORT void concatAndHTMLDecode(const char* str, size_t slen);
157 
159  DLLEXPORT void concatAndHTMLDecode(const char* str);
160 
162 
164  DLLEXPORT void concatDecodeUrl(const char* url);
165 
167  DLLEXPORT int concatDecodeUrl(const QoreString& url, ExceptionSink* xsink);
168 
170 
174  DLLEXPORT int concatEncodeUrl(ExceptionSink* xsink, const QoreString& url, bool encode_all = false);
175 
177 
180  DLLEXPORT int concatDecodeUriRequest(const QoreString& url, ExceptionSink* xsink);
181 
183 
188  DLLEXPORT int concatEncodeUriRequest(ExceptionSink* xsink, const QoreString& url);
189 
191  DLLEXPORT void concatEscape(const QoreString* str, char c, char esc_char, ExceptionSink* xsink);
192 
194  DLLEXPORT void concatEscape(const char* str, char c, char esc_char = '\\');
195 
197  DLLEXPORT void concatAndHTMLEncode(const QoreString* , ExceptionSink* xsink);
198 
200  DLLEXPORT void concat(const QoreString* str, ExceptionSink* xsink);
201 
203 
209  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, ExceptionSink* xsink);
210 
212 
219  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, qore_offset_t len, ExceptionSink* xsink);
220 
222 
227  DLLEXPORT void concat(const QoreString* str, qore_size_t size, ExceptionSink* xsink);
228 
230  DLLEXPORT void concatBase64(const char* buf, qore_size_t size);
231 
233  DLLEXPORT void concatBase64(const BinaryNode* bin);
234 
236  DLLEXPORT void concatBase64(const QoreString* str);
237 
239  DLLEXPORT void concatBase64(const char* buf, qore_size_t size, qore_size_t maxlinelen);
240 
242  DLLEXPORT void concatBase64(const BinaryNode* bin, qore_size_t maxlinelen);
243 
245  DLLEXPORT void concatBase64(const QoreString* str, qore_size_t maxlinelen);
246 
248 
252  DLLEXPORT BinaryNode* parseBase64(ExceptionSink* xsink) const;
253 
255 
259  DLLEXPORT QoreString* parseBase64ToString(ExceptionSink* xsink) const;
260 
262 
267  DLLEXPORT QoreString* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
268 
270  DLLEXPORT void concatHex(const char* buf, qore_size_t size);
271 
273  DLLEXPORT void concatHex(const BinaryNode* bin);
274 
276  DLLEXPORT void concatHex(const QoreString* str);
277 
279 
283  DLLEXPORT BinaryNode* parseHex(ExceptionSink* xsink) const;
284 
286  DLLEXPORT void concat(const DateTime* d);
287 
289  DLLEXPORT void concatISO8601DateTime(const DateTime* d);
290 
292  DLLEXPORT void concat(const char* str);
293 
295  DLLEXPORT void concat(const std::string& str);
296 
298  DLLEXPORT void concat(const char* str, qore_size_t size);
299 
301  DLLEXPORT void concat(const char c);
302 
304 
309  DLLEXPORT int compareSoft(const QoreString* str, ExceptionSink* xsink) const;
310 
312 
316  DLLEXPORT int compare(const QoreString* str) const;
317 
319 
323  DLLEXPORT int compare(const char* str) const;
324 
326 
328  DLLEXPORT bool equal(const QoreString& str) const;
329 
331 
333  DLLEXPORT bool equal(const char* str) const;
334 
336 
342  DLLEXPORT bool equalSoft(const QoreString& str, ExceptionSink* xsink) const;
343 
345 
347  DLLEXPORT bool equalPartial(const QoreString& str) const;
348 
350 
352  DLLEXPORT bool equalPartial(const char* str) const;
353 
355 
361  DLLEXPORT bool equalPartialSoft(const QoreString& str, ExceptionSink* xsink) const;
362 
364 
370  DLLEXPORT bool equalPartialPath(const QoreString& str, ExceptionSink* xsink) const;
371 
373  DLLEXPORT void terminate(qore_size_t size);
374 
376 
378  DLLEXPORT void reserve(qore_size_t size);
379 
381 
383  DLLEXPORT int sprintf(const char* fmt, ...);
384 
386 
388  DLLEXPORT int vsprintf(const char* fmt, va_list args);
389 
391 
393  DLLEXPORT void take(char* str);
394 
396  DLLEXPORT void take(char* str, const QoreEncoding* enc);
398 
399  DLLEXPORT void take(char* str, qore_size_t size);
400 
402  DLLEXPORT void take(char* str, qore_size_t size, const QoreEncoding* enc);
403 
405  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size);
406 
408  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size, const QoreEncoding* enc);
409 
411 
416  DLLEXPORT QoreString* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
417 
419 
422  DLLEXPORT char* giveBuffer();
423 
425  DLLEXPORT void clear();
426 
428 
430  DLLEXPORT void reset();
431 
433 
435  DLLEXPORT void replaceAll(const char* old_str, const char* new_str);
436 
438 
440  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char* str);
441 
443 
448  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str);
449 
451 
453  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str, ExceptionSink* xsink);
454 
456 
458  DLLEXPORT void replaceChar(qore_size_t offset, char c);
459 
461 
465  DLLEXPORT void splice(qore_offset_t offset, ExceptionSink* xsink);
466 
468 
473  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
474 
476 
482  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
483 
485 
491  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString& str, ExceptionSink* xsink);
492 
494 
499  DLLEXPORT QoreString* extract(qore_offset_t offset, ExceptionSink* xsink);
500 
502 
509 
511 
518  DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
519 
521 
526  DLLEXPORT QoreString* substr(qore_offset_t offset, ExceptionSink* xsink) const;
527 
529 
535  DLLEXPORT QoreString* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
536 
538  DLLEXPORT qore_size_t chomp();
539 
541  DLLEXPORT const QoreEncoding* getEncoding() const;
542 
544  DLLEXPORT QoreString* copy() const;
545 
547 
549  DLLEXPORT void tolwr();
550 
552 
554  DLLEXPORT void toupr();
555 
557  DLLEXPORT qore_size_t strlen() const;
558 
560  DLLEXPORT qore_size_t size() const;
561 
563  DLLEXPORT qore_size_t capacity() const;
564 
566  DLLEXPORT const char* getBuffer() const;
567 
569 
571  DLLEXPORT void allocate(unsigned requested_size);
572 
574 
580  DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times);
581 
583 
588  DLLEXPORT int insert(const char* str, qore_size_t pos);
589 
591  DLLEXPORT void addch(char c, unsigned times);
592 
594 
600  DLLEXPORT void concatUTF8FromUnicode(unsigned code);
601 
603 
607  DLLEXPORT int concatUnicode(unsigned code, ExceptionSink* xsink);
608 
610 
614  DLLEXPORT int concatUnicode(unsigned code);
615 
617 
620  DLLEXPORT QoreString* reverse() const;
621 
623  DLLEXPORT void trim_trailing(const char* chars = 0);
624 
626  DLLEXPORT void trim_leading(const char* chars = 0);
627 
629  DLLEXPORT void trim(const char* chars = 0);
630 
632  DLLEXPORT void trim_trailing(char c);
633 
635  DLLEXPORT void trim_single_trailing(char c);
636 
638  DLLEXPORT void trim_leading(char c);
639 
641  DLLEXPORT void trim_single_leading(char c);
642 
644  DLLEXPORT void trim(char c);
645 
647 
651  DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
652 
654 
661  DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink* xsink) const;
662 
664 
671  DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned& len, ExceptionSink* xsink) const;
672 
674  DLLEXPORT void prepend(const char* str);
675 
677  DLLEXPORT void prepend(const char* str, qore_size_t size);
678 
680  DLLEXPORT QoreString& operator=(const QoreString& other);
681 
683  DLLEXPORT QoreString& operator=(const char* other);
684 
686  DLLEXPORT QoreString& operator=(const std::string& other);
687 
689  DLLEXPORT bool operator==(const QoreString& other) const;
690 
692  DLLEXPORT bool operator==(const std::string& other) const;
693 
695  DLLEXPORT bool operator==(const char* other) const;
696 
698 
703  DLLEXPORT char operator[](qore_offset_t pos) const;
704 
706  DLLEXPORT QoreString& operator+=(const char* str);
707 
709  DLLEXPORT QoreString& operator+=(const std::string& str);
710 
712  DLLEXPORT bool empty() const;
713 
715  DLLEXPORT qore_offset_t index(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
716 
718  DLLEXPORT qore_offset_t bindex(const QoreString& needle, qore_offset_t pos) const;
719 
721  DLLEXPORT qore_offset_t bindex(const char* needle, qore_offset_t pos) const;
722 
724  DLLEXPORT qore_offset_t bindex(const std::string& needle, qore_offset_t pos) const;
725 
727 
733  DLLEXPORT qore_offset_t rindex(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
734 
736  DLLEXPORT qore_offset_t brindex(const QoreString& needle, qore_offset_t pos) const;
737 
739  DLLEXPORT qore_offset_t brindex(const char* needle, qore_offset_t pos) const;
740 
742  DLLEXPORT qore_offset_t brindex(const std::string& needle, qore_offset_t pos) const;
743 
745  DLLEXPORT qore_offset_t find(char c, qore_offset_t pos = 0) const;
746 
748  DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos = -1) const;
749 
751 
753  DLLEXPORT bool isDataPrintableAscii() const;
754 
756 
758  DLLEXPORT bool isDataAscii() const;
759 
761  DLLEXPORT int64 toBigInt() const;
762 
764 
769  DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink* xsink) const;
770 
771  // concatenates a qorestring without converting encodings - internal only
772  DLLLOCAL void concat(const QoreString* str);
773 
774  // private constructor
775  DLLLOCAL QoreString(struct qore_string_private* p);
776 };
777 
778 DLLEXPORT QoreString* checkEncoding(const QoreString* str, const QoreEncoding* enc, ExceptionSink* xsink);
779 
780 class QoreStringMaker : public QoreString {
781 private:
783  DLLLOCAL QoreStringMaker(const QoreStringMaker& str);
784 
786  DLLLOCAL QoreStringMaker& operator=(const QoreStringMaker&);
787 
788 public:
790 
792  DLLEXPORT QoreStringMaker(const char* fmt, ...);
793 
795 
797  DLLEXPORT QoreStringMaker(const QoreEncoding* enc, const char* fmt, ...);
798 };
799 
801 
810 class TempString {
811 private:
812  QoreString* str;
813 
815  TempString(const TempString& );
816 
818  TempString& operator=(const TempString& );
819 
821  void* operator new(size_t);
822 
823 public:
825  DLLLOCAL TempString() : str(new QoreString) {
826  }
827 
829  DLLLOCAL TempString(const QoreEncoding* enc) : str(new QoreString(enc)) {
830  }
831 
833  DLLLOCAL TempString(QoreString* s) {
834  str = s;
835  }
836 
838  DLLLOCAL ~TempString() {
839  delete str;
840  }
841 
843  DLLLOCAL QoreString* operator->(){ return str; };
844 
846  DLLLOCAL QoreString* operator*() { return str; };
847 
849  DLLLOCAL operator bool() const { return str != 0; }
850 
852  DLLLOCAL QoreString* release() { QoreString* rv = str; str = 0; return rv; }
853 };
854 
856 
869 private:
870  QoreString* str;
871  bool temp;
872 
874  DLLLOCAL TempEncodingHelper(const TempEncodingHelper& );
875 
877  DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper& );
878 
880  DLLLOCAL void* operator new(size_t);
881 
883  DLLLOCAL void discard_intern() {
884  if (temp && str)
885  delete str;
886  }
887 
889 
894  DLLLOCAL void set_intern(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
895  if (s->getEncoding() != qe) {
896  str = s->convertEncoding(qe, xsink);
897  temp = true;
898  }
899  else {
900  str = const_cast<QoreString* >(s);
901  temp = false;
902  }
903  }
904 
905 public:
907 
912  DLLLOCAL TempEncodingHelper(const QoreString& s, const QoreEncoding* qe, ExceptionSink* xsink) {
913  set_intern(&s, qe, xsink);
914  }
915 
917 
922  DLLLOCAL TempEncodingHelper(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
923  set_intern(s, qe, xsink);
924  }
925 
927  DLLLOCAL TempEncodingHelper() : str(0), temp(false) {
928  }
929 
931  DLLLOCAL ~TempEncodingHelper() {
932  discard_intern();
933  }
934 
936 
945  DLLLOCAL int set(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
946  discard_intern();
947 
948  set_intern(s, qe, xsink);
949  return str != 0;
950  }
951 
953  DLLLOCAL bool is_temp() const {
954  return temp;
955  }
956 
958  DLLLOCAL void makeTemp() {
959  if (!temp && str) {
960  str = new QoreString(*str);
961  temp = true;
962  }
963  }
964 
966  DLLLOCAL const QoreString* operator->(){ return str; };
967 
969  DLLLOCAL const QoreString* operator*() { return str; };
970 
972 
975  DLLLOCAL operator bool() const { return str != 0; }
976 
978 
981  DLLLOCAL char* giveBuffer() {
982  if (!str)
983  return 0;
984  if (temp)
985  return str->giveBuffer();
986  return strdup(str->getBuffer());
987  }
988 };
989 
990 #endif
991 
DLLEXPORT char operator[](qore_offset_t pos) const
returns the byte (not character) at the given location; if the location is invalid, returns 0
DLLEXPORT void trim_trailing(const char *chars=0)
remove trailing whitespace or other characters
DLLEXPORT bool isDataPrintableAscii() const
returns true if the string is empty or only contains printable non-control ASCII characters (ie all c...
DLLEXPORT bool equalSoft(const QoreString &str, ExceptionSink *xsink) const
returns true if the strings are equal, false if not, if the character encodings are different...
DLLEXPORT QoreString()
creates an empty string and assigns the default encoding QCS_DEFAULT
DLLEXPORT BinaryNode * parseHex(ExceptionSink *xsink) const
parses the current string data as hexadecimal-encoded data and returns it as a BinaryNode pointer (ca...
DLLEXPORT bool equalPartialSoft(const QoreString &str, ExceptionSink *xsink) const
returns true if the beginning of the current string matches the argument string, false if not...
DLLEXPORT void setEncoding(const QoreEncoding *new_encoding)
changes the tagged encoding to the given encoding; does not affect the actual string buffer...
struct qore_string_private * priv
the private implementation of QoreString
Definition: QoreString.h:54
defines string encoding functions in Qore
Definition: QoreEncoding.h:80
DLLEXPORT qore_offset_t find(char c, qore_offset_t pos=0) const
returns the byte position of a character (byte) within the string or -1 if not found ...
DLLEXPORT int64 toBigInt() const
returns the value of the string as an int64
DLLEXPORT void concatDecodeUrl(const char *url)
concatenates a URL-decoded version of the c-string passed
DLLEXPORT void replaceAll(const char *old_str, const char *new_str)
replaces all occurences of the first string with the second string
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink *xsink) const
returns the byte position of the given character position in the string or -1 if the string does not ...
DLLEXPORT void concatEscape(const QoreString *str, char c, char esc_char, ExceptionSink *xsink)
concatenates a string and escapes character c with esc_char (converts encodings if necessary) ...
DLLEXPORT void set(const char *str, const QoreEncoding *new_qorecharset=QCS_DEFAULT)
copies the c-string passed and sets the value of the string and its encoding
DLLEXPORT void trim_single_trailing(char c)
remove a single trailing character if present
DLLEXPORT bool equalPartialPath(const QoreString &str, ExceptionSink *xsink) const
returns true if the begining of the current string matches the argument string where either both stri...
DLLEXPORT bool equalPartial(const QoreString &str) const
returns true if the beginning of the current string matches the argument string, false if not...
DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset=0) const
return Unicode code point for character offset, string must be UTF-8
DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos=-1) const
returns the last byte position of a character (byte) within the string or -1 if not found ...
DLLEXPORT void reserve(qore_size_t size)
ensures that at least the given size is available in the string; the string's contents are not affect...
DLLEXPORT bool equal(const QoreString &str) const
returns true if the strings are equal, false if not, if the character encodings are different...
DLLEXPORT void concatHex(const char *buf, qore_size_t size)
concatenates hexidecimal digits corresponding to the binary data passed up to byte "len" ...
DLLEXPORT QoreString * parseBase64ToString(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a QoreString pointer owned by...
DLLLOCAL bool is_temp() const
returns true if a temporary string is being managed
Definition: QoreString.h:953
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
DLLEXPORT char * giveBuffer()
returns the character buffer and leaves the QoreString empty, the caller owns the memory returned (mu...
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
DLLEXPORT void concatISO8601DateTime(const DateTime *d)
concatenates a DateTime value to a string in the format YYYYMMDDTHH:mm:SS <- where the "T" is a liter...
DLLEXPORT qore_size_t capacity() const
returns number of bytes allocated for the string's buffer, capacity is always >= size ...
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:70
long qore_offset_t
used for offsets that could be negative
Definition: common.h:73
DLLEXPORT BinaryNode * parseBase64(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a BinaryNode pointer (caller ...
DLLEXPORT void tolwr()
converts the string to lower-case in place
DLLEXPORT void prepend(const char *str)
prepends the string given to the string, assumes character encoding is the same as the string's ...
DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset"
DLLEXPORT void concatUTF8FromUnicode(unsigned code)
append a UTF-8 character sequence from a unicode code point, assumes the string is tagged with QCS_UT...
DLLEXPORT int concatDecodeUriRequest(const QoreString &url, ExceptionSink *xsink)
concatenates a URI-decoded version of the c-string passed
DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink *xsink) const
return Unicode code point for the single character at the given character (not byte) offset in the st...
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:50
DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char *str)
replaces bytes with the string passed
class used to hold a possibly temporary QoreString pointer, stack only, cannot be dynamically allocat...
Definition: QoreString.h:810
DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times)
insert a character at a certain position in the string a number of times
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
DLLEXPORT int compare(const QoreString *str) const
compares two strings without converting encodings (if the encodings do not match then "this" is deeme...
DLLEXPORT qore_offset_t rindex(const QoreString &needle, qore_offset_t pos, ExceptionSink *xsink) const
returns the character position of a substring searching in reverse from a given position or -1 if not...
DLLEXPORT qore_offset_t index(const QoreString &needle, qore_offset_t pos, ExceptionSink *xsink) const
returns the character position of a substring within the string or -1 if not found ...
DLLEXPORT QoreString * convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const
converts the encoding of the string to the specified encoding, returns 0 if an error occurs...
DLLEXPORT void toupr()
converts the string to upper-case in place
DLLEXPORT qore_size_t length() const
returns the number of characters (not bytes) in the string
DLLLOCAL QoreString * release()
releases the QoreString pointer being managed and sets the internal pointer to 0
Definition: QoreString.h:852
DLLEXPORT bool isDataAscii() const
returns true if the string is empty or has no characters with the high bit set (ie all characters < 1...
DLLEXPORT void concatBase64(const char *buf, qore_size_t size)
concatenates the base64-encoded version of the binary data passed
DLLEXPORT QoreString * reverse() const
return a Qorestring with the characters reversed
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:868
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding for the string
DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned &len, ExceptionSink *xsink) const
return Unicode code point for the given byte offset
DLLEXPORT int insert(const char *str, qore_size_t pos)
inserts a character string at a certain position in the string
DLLEXPORT void concatAndHTMLEncode(const char *str)
concatenates HTML-encoded version of the c-string passed
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLEXPORT bool empty() const
returns true if the string is empty, false if not
DLLLOCAL const QoreString * operator*()
returns the string being managed
Definition: QoreString.h:969
DLLLOCAL ~TempString()
deletes the QoreString pointer being managed
Definition: QoreString.h:838
DLLLOCAL TempEncodingHelper(const QoreString &s, const QoreEncoding *qe, ExceptionSink *xsink)
converts the given string to the required encoding if necessary
Definition: QoreString.h:912
DLLEXPORT bool operator==(const QoreString &other) const
returns true if the other string is equal to this string (encodings also must be equal) ...
DLLEXPORT qore_offset_t bindex(const QoreString &needle, qore_offset_t pos) const
returns the byte position of a substring within the string or -1 if not found
DLLEXPORT int concatEncodeUrl(ExceptionSink *xsink, const QoreString &url, bool encode_all=false)
concatenates a URL-encoded version of the c-string passed
DLLEXPORT void trim_leading(const char *chars=0)
remove leading whitespace or other characters
DLLEXPORT void replaceChar(qore_size_t offset, char c)
replaces a byte with the byte passed
DLLEXPORT void addch(char c, unsigned times)
append a character to the string a number of times
DLLLOCAL TempString(QoreString *s)
populates the object with the QoreString pointer to be managed
Definition: QoreString.h:833
DLLLOCAL void makeTemp()
ensures that the object is holding a temporary value
Definition: QoreString.h:958
DLLEXPORT void terminate(qore_size_t size)
terminates the string at byte position "size", the string is reallocated if necessary ...
DLLLOCAL TempEncodingHelper()
creates an empty TempEncodingHelperObject that may be initialized with TempEncodingHelper::set() late...
Definition: QoreString.h:927
DLLLOCAL ~TempEncodingHelper()
deletes any temporary string being managed by the object
Definition: QoreString.h:931
DLLEXPORT void trim(const char *chars=0)
remove leading and trailing whitespace or other characters
DLLLOCAL QoreString * operator->()
returns the QoreString pointer being managed
Definition: QoreString.h:843
DLLEXPORT qore_size_t strlen() const
returns number of bytes in the string (not including the null pointer)
DLLEXPORT int concatUnicode(unsigned code, ExceptionSink *xsink)
append a character sequence from a unicode code point (returns 0 for OK, -1 for exception) ...
DLLEXPORT QoreString & operator+=(const char *str)
concatenates the characters to the string; assumes the string to be concatenated is already in the ch...
DLLLOCAL TempEncodingHelper(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink)
converts the given string to the required encoding if necessary
Definition: QoreString.h:922
DLLEXPORT qore_size_t chomp()
removes a single \n\r or \n from the end of the string and returns the number of characters removed ...
DLLEXPORT ~QoreString()
frees any memory allocated by the string
DLLEXPORT void takeAndTerminate(char *str, qore_size_t size)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
DLLLOCAL TempString(const QoreEncoding *enc)
populates the object with a new QoreString in a specific encoding that this object will manage ...
Definition: QoreString.h:829
DLLEXPORT qore_offset_t brindex(const QoreString &needle, qore_offset_t pos) const
returns the byte position of a substring within the string searching in reverse from a given position...
DLLEXPORT QoreString * extract(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset" and returns a string of the characte...
DLLEXPORT void allocate(unsigned requested_size)
Ensure the internal buffer has at least expected size in bytes.
DLLLOCAL char * giveBuffer()
returns a char pointer of the string, the caller owns the pointer returned (it must be manually freed...
Definition: QoreString.h:981
DLLEXPORT void reset()
reset string to zero length; memory is deallocated; string encoding is reset to QCS_DEFAULT ...
DLLEXPORT void clear()
reset string to zero length; memory is not deallocated; string encoding does not change ...
DLLLOCAL QoreString * operator*()
returns the QoreString pointer being managed
Definition: QoreString.h:846
DLLEXPORT void concatAndHTMLDecode(const QoreString *str)
concatenates HTML-decoded version of the c-string passed
DLLEXPORT void trim_single_leading(char c)
remove a single leading character if present
DLLLOCAL int set(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink)
discards any current state and sets and converts (if necessary) a new string to the desired encoding ...
Definition: QoreString.h:945
DLLEXPORT int vsprintf(const char *fmt, va_list args)
this will concatentate a formatted string to the existing string according to the format string and t...
DLLEXPORT QoreString * substr(qore_offset_t offset, ExceptionSink *xsink) const
returns a new string consisting of all the characters from the current string starting with character...
DLLLOCAL const QoreString * operator->()
returns the string being managed
Definition: QoreString.h:966
DLLEXPORT qore_size_t size() const
returns number of bytes in the string (not including the null pointer)
DLLEXPORT void take(char *str)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
DLLLOCAL TempString()
populates the object with a new QoreString that this object will manage
Definition: QoreString.h:825
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
DLLEXPORT int concatEncodeUriRequest(ExceptionSink *xsink, const QoreString &url)
concatenates a URI-encoded version of the c-string passed
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT int compareSoft(const QoreString *str, ExceptionSink *xsink) const
compares the string with another string, performing character set encoding conversion if necessary ...
DLLEXPORT const char * getBuffer() const
returns the string's buffer; this data should not be changed