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 protected:
53  struct qore_string_private* priv;
54 
55  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, QoreString* extract = 0);
56  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char* str, qore_size_t str_len, QoreString* extract = 0);
57  DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink* xsink, QoreString* extract = 0);
58  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink, QoreString* extract = 0);
59  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString* str, ExceptionSink* xsink, QoreString* extract = 0);
60  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset) const;
61  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset, qore_offset_t length) const;
62  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, ExceptionSink* xsink) const;
63  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
64 
65  // writes a new QoreString with the characters reversed of the "this" QoreString
66  // assumes the encoding is the same and the length is 0
67  DLLLOCAL void concat_reverse(QoreString* targ) const;
68 
69  DLLLOCAL int snprintf(size_t size, const char* fmt, ...);
70  DLLLOCAL int vsnprintf(size_t size, const char* fmt, va_list args);
71  DLLLOCAL static int convert_encoding_intern(const char* src, qore_size_t src_len, const QoreEncoding* from, QoreString& targ, const QoreEncoding* to, ExceptionSink* xsink);
72 
73 public:
75  DLLEXPORT QoreString();
76 
78  DLLEXPORT QoreString(bool b);
79 
81  DLLEXPORT QoreString(const char* str);
82 
84  DLLEXPORT QoreString(const char* str, const QoreEncoding* new_qorecharset);
85 
87  DLLEXPORT QoreString(const QoreEncoding* new_qorecharset);
88 
90  DLLEXPORT QoreString(const char* str, qore_size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
91 
93  DLLEXPORT QoreString(const std::string& str, const QoreEncoding* new_encoding = QCS_DEFAULT);
94 
96  DLLEXPORT QoreString(char c);
97 
99  DLLEXPORT QoreString(const QoreString& str);
100 
102  DLLEXPORT QoreString(const QoreString* str);
103 
105  DLLEXPORT QoreString(const QoreString* str, qore_size_t len);
106 
108  DLLEXPORT QoreString(int64 i);
109 
111  DLLEXPORT QoreString(double f);
112 
114  DLLEXPORT QoreString(const DateTime* date);
115 
117  DLLEXPORT QoreString(const BinaryNode* bin);
118 
120  DLLEXPORT QoreString(const BinaryNode* bin, qore_size_t maxlinelen);
121 
123  DLLEXPORT QoreString(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
124 
126  DLLEXPORT ~QoreString();
127 
129 
131  DLLEXPORT qore_size_t length() const;
132 
134  DLLEXPORT void set(const char* str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
135 
137  DLLEXPORT void set(const std::string& str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
138 
140  DLLEXPORT void set(const QoreString* str);
141 
143  DLLEXPORT void set(const QoreString& str);
144 
146  DLLEXPORT void setEncoding(const QoreEncoding* new_encoding);
147 
149  DLLEXPORT void concatAndHTMLEncode(const char* str);
150 
152  DLLEXPORT void concatAndHTMLDecode(const QoreString* str);
153 
155  DLLEXPORT void concatAndHTMLDecode(const char* str, size_t slen);
156 
158  DLLEXPORT void concatAndHTMLDecode(const char* str);
159 
161 
163  DLLEXPORT void concatDecodeUrl(const char* url);
164 
166  DLLEXPORT int concatDecodeUrl(const QoreString& url, ExceptionSink* xsink);
167 
169 
173  DLLEXPORT int concatEncodeUrl(ExceptionSink* xsink, const QoreString& url, bool encode_all = false);
174 
176  DLLEXPORT void concatEscape(const QoreString* str, char c, char esc_char, ExceptionSink* xsink);
177 
179  DLLEXPORT void concatEscape(const char* str, char c, char esc_char = '\\');
180 
182  DLLEXPORT void concatAndHTMLEncode(const QoreString* , ExceptionSink* xsink);
183 
185  DLLEXPORT void concat(const QoreString* str, ExceptionSink* xsink);
186 
188 
194  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, ExceptionSink* xsink);
195 
197 
204  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, qore_offset_t len, ExceptionSink* xsink);
205 
207 
212  DLLEXPORT void concat(const QoreString* str, qore_size_t size, ExceptionSink* xsink);
213 
215  DLLEXPORT void concatBase64(const char* buf, qore_size_t size);
216 
218  DLLEXPORT void concatBase64(const BinaryNode* bin);
219 
221  DLLEXPORT void concatBase64(const QoreString* str);
222 
224  DLLEXPORT void concatBase64(const char* buf, qore_size_t size, qore_size_t maxlinelen);
225 
227  DLLEXPORT void concatBase64(const BinaryNode* bin, qore_size_t maxlinelen);
228 
230  DLLEXPORT void concatBase64(const QoreString* str, qore_size_t maxlinelen);
231 
233 
237  DLLEXPORT BinaryNode* parseBase64(ExceptionSink* xsink) const;
238 
240 
244  DLLEXPORT QoreString* parseBase64ToString(ExceptionSink* xsink) const;
245 
247 
252  DLLEXPORT QoreString* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
253 
255  DLLEXPORT void concatHex(const char* buf, qore_size_t size);
256 
258  DLLEXPORT void concatHex(const BinaryNode* bin);
259 
261  DLLEXPORT void concatHex(const QoreString* str);
262 
264 
268  DLLEXPORT BinaryNode* parseHex(ExceptionSink* xsink) const;
269 
271  DLLEXPORT void concat(const DateTime* d);
272 
274  DLLEXPORT void concatISO8601DateTime(const DateTime* d);
275 
277  DLLEXPORT void concat(const char* str);
278 
280  DLLEXPORT void concat(const std::string& str);
281 
283  DLLEXPORT void concat(const char* str, qore_size_t size);
284 
286  DLLEXPORT void concat(const char c);
287 
289 
294  DLLEXPORT int compareSoft(const QoreString* str, ExceptionSink* xsink) const;
295 
297 
301  DLLEXPORT int compare(const QoreString* str) const;
302 
304 
308  DLLEXPORT int compare(const char* str) const;
309 
311 
313  DLLEXPORT bool equal(const QoreString& str) const;
314 
316 
318  DLLEXPORT bool equal(const char* str) const;
319 
321 
327  DLLEXPORT bool equalSoft(const QoreString& str, ExceptionSink* xsink) const;
328 
330 
332  DLLEXPORT bool equalPartial(const QoreString& str) const;
333 
335 
337  DLLEXPORT bool equalPartial(const char* str) const;
338 
340 
346  DLLEXPORT bool equalPartialSoft(const QoreString& str, ExceptionSink* xsink) const;
347 
349 
355  DLLEXPORT bool equalPartialPath(const QoreString& str, ExceptionSink* xsink) const;
356 
358  DLLEXPORT void terminate(qore_size_t size);
359 
361 
363  DLLEXPORT void reserve(qore_size_t size);
364 
366 
368  DLLEXPORT int sprintf(const char* fmt, ...);
369 
371 
373  DLLEXPORT int vsprintf(const char* fmt, va_list args);
374 
376 
378  DLLEXPORT void take(char* str);
379 
381  DLLEXPORT void take(char* str, const QoreEncoding* enc);
383 
384  DLLEXPORT void take(char* str, qore_size_t size);
385 
387  DLLEXPORT void take(char* str, qore_size_t size, const QoreEncoding* enc);
388 
390  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size);
391 
393  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size, const QoreEncoding* enc);
394 
396 
401  DLLEXPORT QoreString* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
402 
404 
407  DLLEXPORT char* giveBuffer();
408 
410  DLLEXPORT void clear();
411 
413 
415  DLLEXPORT void reset();
416 
418 
420  DLLEXPORT void replaceAll(const char* old_str, const char* new_str);
421 
423 
425  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char* str);
426 
428 
433  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str);
434 
436 
438  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str, ExceptionSink* xsink);
439 
441 
443  DLLEXPORT void replaceChar(qore_size_t offset, char c);
444 
446 
450  DLLEXPORT void splice(qore_offset_t offset, ExceptionSink* xsink);
451 
453 
458  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
459 
461 
467  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
468 
470 
476  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString& str, ExceptionSink* xsink);
477 
479 
484  DLLEXPORT QoreString* extract(qore_offset_t offset, ExceptionSink* xsink);
485 
487 
494 
496 
503  DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
504 
506 
511  DLLEXPORT QoreString* substr(qore_offset_t offset, ExceptionSink* xsink) const;
512 
514 
520  DLLEXPORT QoreString* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
521 
523  DLLEXPORT qore_size_t chomp();
524 
526  DLLEXPORT const QoreEncoding* getEncoding() const;
527 
529  DLLEXPORT QoreString* copy() const;
530 
532 
534  DLLEXPORT void tolwr();
535 
537 
539  DLLEXPORT void toupr();
540 
542  DLLEXPORT qore_size_t strlen() const;
543 
545  DLLEXPORT qore_size_t size() const;
546 
548  DLLEXPORT qore_size_t capacity() const;
549 
551  DLLEXPORT const char* getBuffer() const;
552 
554 
556  DLLEXPORT void allocate(unsigned requested_size);
557 
559 
565  DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times);
566 
568 
573  DLLEXPORT int insert(const char* str, qore_size_t pos);
574 
576  DLLEXPORT void addch(char c, unsigned times);
577 
579 
585  DLLEXPORT void concatUTF8FromUnicode(unsigned code);
586 
588 
592  DLLEXPORT int concatUnicode(unsigned code, ExceptionSink* xsink);
593 
595 
599  DLLEXPORT int concatUnicode(unsigned code);
600 
602 
605  DLLEXPORT QoreString* reverse() const;
606 
608  DLLEXPORT void trim_trailing(const char* chars = 0);
609 
611  DLLEXPORT void trim_leading(const char* chars = 0);
612 
614  DLLEXPORT void trim(const char* chars = 0);
615 
617  DLLEXPORT void trim_trailing(char c);
618 
620  DLLEXPORT void trim_single_trailing(char c);
621 
623  DLLEXPORT void trim_leading(char c);
624 
626  DLLEXPORT void trim_single_leading(char c);
627 
629  DLLEXPORT void trim(char c);
630 
632 
636  DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
637 
639 
646  DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink* xsink) const;
647 
649 
656  DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned& len, ExceptionSink* xsink) const;
657 
659  DLLEXPORT void prepend(const char* str);
660 
662  DLLEXPORT void prepend(const char* str, qore_size_t size);
663 
665  DLLEXPORT QoreString& operator=(const QoreString& other);
666 
668  DLLEXPORT QoreString& operator=(const char* other);
669 
671  DLLEXPORT QoreString& operator=(const std::string& other);
672 
674  DLLEXPORT bool operator==(const QoreString& other) const;
675 
677  DLLEXPORT bool operator==(const std::string& other) const;
678 
680  DLLEXPORT bool operator==(const char* other) const;
681 
683 
688  DLLEXPORT char operator[](qore_offset_t pos) const;
689 
691  DLLEXPORT QoreString& operator+=(const char* str);
692 
694  DLLEXPORT QoreString& operator+=(const std::string& str);
695 
697  DLLEXPORT bool empty() const;
698 
700  DLLEXPORT qore_offset_t index(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
701 
703  DLLEXPORT qore_offset_t bindex(const QoreString& needle, qore_offset_t pos) const;
704 
706  DLLEXPORT qore_offset_t bindex(const char* needle, qore_offset_t pos) const;
707 
709  DLLEXPORT qore_offset_t bindex(const std::string& needle, qore_offset_t pos) const;
710 
712 
718  DLLEXPORT qore_offset_t rindex(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
719 
721  DLLEXPORT qore_offset_t brindex(const QoreString& needle, qore_offset_t pos) const;
722 
724  DLLEXPORT qore_offset_t brindex(const char* needle, qore_offset_t pos) const;
725 
727  DLLEXPORT qore_offset_t brindex(const std::string& needle, qore_offset_t pos) const;
728 
730  DLLEXPORT qore_offset_t find(char c, qore_offset_t pos = 0) const;
731 
733  DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos = -1) const;
734 
736 
738  DLLEXPORT bool isDataPrintableAscii() const;
739 
741 
743  DLLEXPORT bool isDataAscii() const;
744 
746  DLLEXPORT int64 toBigInt() const;
747 
749 
754  DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink* xsink) const;
755 
756  // concatenates a qorestring without converting encodings - internal only
757  DLLLOCAL void concat(const QoreString* str);
758 
759  // private constructor
760  DLLLOCAL QoreString(struct qore_string_private* p);
761 };
762 
763 DLLEXPORT QoreString* checkEncoding(const QoreString* str, const QoreEncoding* enc, ExceptionSink* xsink);
764 
765 class QoreStringMaker : public QoreString {
766 private:
768  DLLLOCAL QoreStringMaker(const QoreStringMaker& str);
769 
771  DLLLOCAL QoreStringMaker& operator=(const QoreStringMaker&);
772 
773 public:
775 
777  DLLEXPORT QoreStringMaker(const char* fmt, ...);
778 
780 
782  DLLEXPORT QoreStringMaker(const QoreEncoding* enc, const char* fmt, ...);
783 };
784 
786 
795 class TempString {
796 private:
797  QoreString* str;
798 
800  TempString(const TempString& );
801 
803  TempString& operator=(const TempString& );
804 
806  void* operator new(size_t);
807 
808 public:
810  DLLLOCAL TempString() : str(new QoreString) {
811  }
812 
814  DLLLOCAL TempString(const QoreEncoding* enc) : str(new QoreString(enc)) {
815  }
816 
818  DLLLOCAL TempString(QoreString* s) {
819  str = s;
820  }
821 
823  DLLLOCAL ~TempString() {
824  delete str;
825  }
826 
828  DLLLOCAL QoreString* operator->(){ return str; };
829 
831  DLLLOCAL QoreString* operator*() { return str; };
832 
834  DLLLOCAL operator bool() const { return str != 0; }
835 
837  DLLLOCAL QoreString* release() { QoreString* rv = str; str = 0; return rv; }
838 };
839 
841 
854 private:
855  QoreString* str;
856  bool temp;
857 
859  DLLLOCAL TempEncodingHelper(const TempEncodingHelper& );
860 
862  DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper& );
863 
865  DLLLOCAL void* operator new(size_t);
866 
868  DLLLOCAL void discard_intern() {
869  if (temp && str)
870  delete str;
871  }
872 
874 
879  DLLLOCAL void set_intern(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
880  if (s->getEncoding() != qe) {
881  str = s->convertEncoding(qe, xsink);
882  temp = true;
883  }
884  else {
885  str = const_cast<QoreString* >(s);
886  temp = false;
887  }
888  }
889 
890 public:
892 
897  DLLLOCAL TempEncodingHelper(const QoreString& s, const QoreEncoding* qe, ExceptionSink* xsink) {
898  set_intern(&s, qe, xsink);
899  }
900 
902 
907  DLLLOCAL TempEncodingHelper(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
908  set_intern(s, qe, xsink);
909  }
910 
912  DLLLOCAL TempEncodingHelper() : str(0), temp(false) {
913  }
914 
916  DLLLOCAL ~TempEncodingHelper() {
917  discard_intern();
918  }
919 
921 
930  DLLLOCAL int set(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
931  discard_intern();
932 
933  set_intern(s, qe, xsink);
934  return str != 0;
935  }
936 
938  DLLLOCAL bool is_temp() const {
939  return temp;
940  }
941 
943  DLLLOCAL void makeTemp() {
944  if (!temp && str) {
945  str = new QoreString(*str);
946  temp = true;
947  }
948  }
949 
951  DLLLOCAL const QoreString* operator->(){ return str; };
952 
954  DLLLOCAL const QoreString* operator*() { return str; };
955 
957 
960  DLLLOCAL operator bool() const { return str != 0; }
961 
963 
966  DLLLOCAL char* giveBuffer() {
967  if (!str)
968  return 0;
969  if (temp)
970  return str->giveBuffer();
971  return strdup(str->getBuffer());
972  }
973 };
974 
975 #endif
976 
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:53
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:938
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 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:795
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:837
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:853
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:954
DLLLOCAL ~TempString()
deletes the QoreString pointer being managed
Definition: QoreString.h:823
DLLLOCAL TempEncodingHelper(const QoreString &s, const QoreEncoding *qe, ExceptionSink *xsink)
converts the given string to the required encoding if necessary
Definition: QoreString.h:897
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:818
DLLLOCAL void makeTemp()
ensures that the object is holding a temporary value
Definition: QoreString.h:943
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:912
DLLLOCAL ~TempEncodingHelper()
deletes any temporary string being managed by the object
Definition: QoreString.h:916
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:828
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:907
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:814
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:966
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:831
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:930
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:951
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:810
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
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