Qore Programming Language - C/C++ Library  0.8.13.8
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 - 2017 Qore Technologies, s.r.o.
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 
49 #define CE_HTML (1 << 0)
51 #define CE_XML (1 << 1)
53 #define CE_NONASCII (1 << 2)
55 #define CE_XHTML (CE_HTML | CE_XML)
57 #define CE_ALL (CE_XHTML | CE_NONASCII)
59 
60 
62 
65 #define CD_HTML (1 << 0)
67 #define CD_XML (1 << 1)
69 #define CD_NUM_REF (1 << 2)
71 #define CD_XHTML (CD_HTML | CD_XML)
73 #define CD_ALL (CD_XHTML | CD_NUM_REF)
75 
76 
78 
82 class QoreString {
83  friend struct qore_string_private;
84 protected:
86  struct qore_string_private* priv;
87 
88  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, QoreString* extract = 0);
89  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char* str, qore_size_t str_len, QoreString* extract = 0);
90  DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink* xsink, QoreString* extract = 0);
91  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink, QoreString* extract = 0);
92  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString* str, ExceptionSink* xsink, QoreString* extract = 0);
93  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset) const;
94  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset, qore_offset_t length) const;
95  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, ExceptionSink* xsink) const;
96  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
97 
98  // writes a new QoreString with the characters reversed of the "this" QoreString
99  // assumes the encoding is the same and the length is 0
100  DLLLOCAL void concat_reverse(QoreString* targ) const;
101 
102  DLLLOCAL int snprintf(size_t size, const char* fmt, ...);
103  DLLLOCAL int vsnprintf(size_t size, const char* fmt, va_list args);
104 
105 public:
107  DLLEXPORT QoreString();
108 
110  DLLEXPORT QoreString(bool b);
111 
113  DLLEXPORT QoreString(const char* str);
114 
116  DLLEXPORT QoreString(const char* str, const QoreEncoding* new_qorecharset);
117 
119  DLLEXPORT QoreString(const QoreEncoding* new_qorecharset);
120 
122  DLLEXPORT QoreString(const char* str, qore_size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
123 
125  DLLEXPORT QoreString(const std::string& str, const QoreEncoding* new_encoding = QCS_DEFAULT);
126 
128  DLLEXPORT QoreString(char c);
129 
131  DLLEXPORT QoreString(const QoreString& str);
132 
134  DLLEXPORT QoreString(const QoreString* str);
135 
137  DLLEXPORT QoreString(const QoreString* str, qore_size_t len);
138 
140  DLLEXPORT QoreString(int64 i);
141 
143  DLLEXPORT QoreString(double f);
144 
146  DLLEXPORT QoreString(const DateTime* date);
147 
149  DLLEXPORT QoreString(const BinaryNode* bin);
150 
152  DLLEXPORT QoreString(const BinaryNode* bin, qore_size_t maxlinelen);
153 
155  DLLEXPORT QoreString(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
156 
158  DLLEXPORT ~QoreString();
159 
161 
163  DLLEXPORT qore_size_t length() const;
164 
166  DLLEXPORT void set(const char* str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
167 
169  DLLEXPORT void set(const std::string& str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
170 
172  DLLEXPORT void set(const QoreString* str);
173 
175  DLLEXPORT void set(const QoreString& str);
176 
178  DLLEXPORT void set(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
179 
181  DLLEXPORT void setEncoding(const QoreEncoding* new_encoding);
182 
184 
194  DLLEXPORT int concatEncode(ExceptionSink* xsink, const QoreString& str, unsigned code = CE_XHTML);
195 
197 
209  DLLEXPORT int concatDecode(ExceptionSink* xsink, const QoreString& str, unsigned code = CD_ALL);
210 
212 
215  DLLEXPORT void concatAndHTMLEncode(const char* str);
216 
218 
221  DLLEXPORT void concatAndHTMLDecode(const QoreString* str);
222 
224 
227  DLLEXPORT void concatAndHTMLDecode(const char* str, size_t slen);
228 
230 
233  DLLEXPORT void concatAndHTMLDecode(const char* str);
234 
236 
238  DLLEXPORT void concatDecodeUrl(const char* url);
239 
241  DLLEXPORT int concatDecodeUrl(const QoreString& url, ExceptionSink* xsink);
242 
244 
248  DLLEXPORT int concatEncodeUrl(ExceptionSink* xsink, const QoreString& url, bool encode_all = false);
249 
251 
254  DLLEXPORT int concatDecodeUriRequest(const QoreString& url, ExceptionSink* xsink);
255 
257 
262  DLLEXPORT int concatEncodeUriRequest(ExceptionSink* xsink, const QoreString& url);
263 
265  DLLEXPORT void concatEscape(const QoreString* str, char c, char esc_char, ExceptionSink* xsink);
266 
268  DLLEXPORT void concatEscape(const char* str, char c, char esc_char = '\\');
269 
271 
277  DLLEXPORT void concatAndHTMLEncode(const QoreString* str, ExceptionSink* xsink);
278 
280  DLLEXPORT void concat(const QoreString* str, ExceptionSink* xsink);
281 
283 
289  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, ExceptionSink* xsink);
290 
292 
299  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, qore_offset_t len, ExceptionSink* xsink);
300 
302 
307  DLLEXPORT void concat(const QoreString* str, qore_size_t size, ExceptionSink* xsink);
308 
310  DLLEXPORT void concatBase64(const char* buf, qore_size_t size);
311 
313  DLLEXPORT void concatBase64(const BinaryNode* bin);
314 
316  DLLEXPORT void concatBase64(const QoreString* str);
317 
319  DLLEXPORT void concatBase64(const char* buf, qore_size_t size, qore_size_t maxlinelen);
320 
322  DLLEXPORT void concatBase64(const BinaryNode* bin, qore_size_t maxlinelen);
323 
325  DLLEXPORT void concatBase64(const QoreString* str, qore_size_t maxlinelen);
326 
328 
332  DLLEXPORT BinaryNode* parseBase64(ExceptionSink* xsink) const;
333 
335 
339  DLLEXPORT QoreString* parseBase64ToString(ExceptionSink* xsink) const;
340 
342 
347  DLLEXPORT QoreString* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
348 
350  DLLEXPORT void concatHex(const char* buf, qore_size_t size);
351 
353  DLLEXPORT void concatHex(const BinaryNode* bin);
354 
356  DLLEXPORT void concatHex(const QoreString* str);
357 
359 
363  DLLEXPORT BinaryNode* parseHex(ExceptionSink* xsink) const;
364 
366  DLLEXPORT void concat(const DateTime* d);
367 
369  DLLEXPORT void concatISO8601DateTime(const DateTime* d);
370 
372  DLLEXPORT void concat(const char* str);
373 
375  DLLEXPORT void concat(const std::string& str);
376 
378  DLLEXPORT void concat(const char* str, qore_size_t size);
379 
381  DLLEXPORT void concat(const char c);
382 
384 
389  DLLEXPORT int compareSoft(const QoreString* str, ExceptionSink* xsink) const;
390 
392 
396  DLLEXPORT int compare(const QoreString* str) const;
397 
399 
403  DLLEXPORT int compare(const char* str) const;
404 
406 
408  DLLEXPORT bool equal(const QoreString& str) const;
409 
411 
413  DLLEXPORT bool equal(const char* str) const;
414 
416 
422  DLLEXPORT bool equalSoft(const QoreString& str, ExceptionSink* xsink) const;
423 
425 
427  DLLEXPORT bool equalPartial(const QoreString& str) const;
428 
430 
432  DLLEXPORT bool equalPartial(const char* str) const;
433 
435 
441  DLLEXPORT bool equalPartialSoft(const QoreString& str, ExceptionSink* xsink) const;
442 
444 
450  DLLEXPORT bool equalPartialPath(const QoreString& str, ExceptionSink* xsink) const;
451 
453  DLLEXPORT void terminate(qore_size_t size);
454 
456 
458  DLLEXPORT void reserve(qore_size_t size);
459 
461 
463  DLLEXPORT int sprintf(const char* fmt, ...);
464 
466 
468  DLLEXPORT int vsprintf(const char* fmt, va_list args);
469 
471 
473  DLLEXPORT void take(char* str);
474 
476  DLLEXPORT void take(char* str, const QoreEncoding* enc);
478 
479  DLLEXPORT void take(char* str, qore_size_t size);
480 
482  DLLEXPORT void take(char* str, qore_size_t size, const QoreEncoding* enc);
483 
485  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size);
486 
488  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size, const QoreEncoding* enc);
489 
491 
496  DLLEXPORT QoreString* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
497 
499 
502  DLLEXPORT char* giveBuffer();
503 
505  DLLEXPORT void clear();
506 
508 
510  DLLEXPORT void reset();
511 
513 
515  DLLEXPORT void replaceAll(const char* old_str, const char* new_str);
516 
518 
520  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char* str);
521 
523 
528  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str);
529 
531 
533  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str, ExceptionSink* xsink);
534 
536 
538  DLLEXPORT void replaceChar(qore_size_t offset, char c);
539 
541 
545  DLLEXPORT void splice(qore_offset_t offset, ExceptionSink* xsink);
546 
548 
553  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
554 
556 
562  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
563 
565 
571  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString& str, ExceptionSink* xsink);
572 
574 
579  DLLEXPORT QoreString* extract(qore_offset_t offset, ExceptionSink* xsink);
580 
582 
589 
591 
598  DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
599 
601 
606  DLLEXPORT QoreString* substr(qore_offset_t offset, ExceptionSink* xsink) const;
607 
609 
615  DLLEXPORT QoreString* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
616 
618  DLLEXPORT qore_size_t chomp();
619 
621  DLLEXPORT const QoreEncoding* getEncoding() const;
622 
624  DLLEXPORT QoreString* copy() const;
625 
627 
629  DLLEXPORT void tolwr();
630 
632 
634  DLLEXPORT void toupr();
635 
637  DLLEXPORT qore_size_t strlen() const;
638 
640  DLLEXPORT qore_size_t size() const;
641 
643  DLLEXPORT qore_size_t capacity() const;
644 
646  DLLEXPORT const char* getBuffer() const;
647 
649  DLLEXPORT const char* c_str() const;
650 
652 
654  DLLEXPORT void allocate(unsigned requested_size);
655 
657 
663  DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times);
664 
666 
671  DLLEXPORT int insert(const char* str, qore_size_t pos);
672 
674  DLLEXPORT void addch(char c, unsigned times);
675 
677 
683  DLLEXPORT void concatUTF8FromUnicode(unsigned code);
684 
686 
690  DLLEXPORT int concatUnicode(unsigned code, ExceptionSink* xsink);
691 
693 
697  DLLEXPORT int concatUnicode(unsigned code);
698 
700 
703  DLLEXPORT QoreString* reverse() const;
704 
706 
708  DLLEXPORT void trim_trailing(const char* chars = 0);
709 
711 
713  DLLEXPORT void trim_leading(const char* chars = 0);
714 
716 
718  DLLEXPORT void trim(const char* chars = 0);
719 
721 
723  DLLEXPORT void trim_trailing(char c);
724 
726 
728  DLLEXPORT void trim_single_trailing(char c);
729 
731 
733  DLLEXPORT void trim_leading(char c);
734 
736 
738  DLLEXPORT void trim_single_leading(char c);
739 
741 
743  DLLEXPORT void trim(char c);
744 
746 
752  DLLEXPORT int trim(ExceptionSink* xsink, const QoreString* chars = nullptr);
753 
755 
761  DLLEXPORT int trimLeading(ExceptionSink* xsink, const QoreString* chars = nullptr);
762 
764 
770  DLLEXPORT int trimTrailing(ExceptionSink* xsink, const QoreString* chars = nullptr);
771 
773 
777  DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
778 
780 
785  DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink* xsink) const;
786 
788 
796  DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned& len, ExceptionSink* xsink) const;
797 
799  DLLEXPORT void prepend(const char* str);
800 
802  DLLEXPORT void prepend(const char* str, qore_size_t size);
803 
805  DLLEXPORT QoreString& operator=(const QoreString& other);
806 
808  DLLEXPORT QoreString& operator=(const char* other);
809 
811  DLLEXPORT QoreString& operator=(const std::string& other);
812 
814  DLLEXPORT bool operator==(const QoreString& other) const;
815 
817  DLLEXPORT bool operator==(const std::string& other) const;
818 
820  DLLEXPORT bool operator==(const char* other) const;
821 
823  DLLLOCAL bool operator!=(const QoreString& other) const {
824  return !(*this == other);
825  }
826 
828  DLLLOCAL bool operator!=(const std::string& other) const {
829  return !(*this == other);
830  }
831 
833  DLLLOCAL bool operator!=(const char* other) const {
834  return !(*this == other);
835  }
836 
838 
843  DLLEXPORT char operator[](qore_offset_t pos) const;
844 
846  DLLEXPORT QoreString& operator+=(const char* str);
847 
849  DLLEXPORT QoreString& operator+=(const std::string& str);
850 
852  DLLEXPORT bool empty() const;
853 
855  DLLEXPORT qore_offset_t index(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
856 
858  DLLEXPORT qore_offset_t bindex(const QoreString& needle, qore_offset_t pos) const;
859 
861  DLLEXPORT qore_offset_t bindex(const char* needle, qore_offset_t pos) const;
862 
864  DLLEXPORT qore_offset_t bindex(const std::string& needle, qore_offset_t pos) const;
865 
867 
873  DLLEXPORT qore_offset_t rindex(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
874 
876  DLLEXPORT qore_offset_t brindex(const QoreString& needle, qore_offset_t pos) const;
877 
879  DLLEXPORT qore_offset_t brindex(const char* needle, qore_offset_t pos) const;
880 
882  DLLEXPORT qore_offset_t brindex(const std::string& needle, qore_offset_t pos) const;
883 
885  DLLEXPORT qore_offset_t find(char c, qore_offset_t pos = 0) const;
886 
888  DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos = -1) const;
889 
891  DLLEXPORT qore_offset_t findAny(const char *str, qore_offset_t pos = 0) const;
892 
894  DLLEXPORT qore_offset_t rfindAny(const char *str, qore_offset_t pos = -1) const;
895 
897 
899  DLLEXPORT bool isDataPrintableAscii() const;
900 
902 
904  DLLEXPORT bool isDataAscii() const;
905 
907  DLLEXPORT int64 toBigInt() const;
908 
910 
915  DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink* xsink) const;
916 
917  // concatenates a qorestring without converting encodings - internal only
918  DLLLOCAL void concat(const QoreString* str);
919 
920  // private constructor
921  DLLLOCAL QoreString(struct qore_string_private* p);
922 };
923 
924 DLLEXPORT QoreString* checkEncoding(const QoreString* str, const QoreEncoding* enc, ExceptionSink* xsink);
925 
926 class QoreStringMaker : public QoreString {
927 private:
929  DLLLOCAL QoreStringMaker(const QoreStringMaker& str);
930 
932  DLLLOCAL QoreStringMaker& operator=(const QoreStringMaker&);
933 
934 public:
936 
938  DLLEXPORT QoreStringMaker(const char* fmt, ...);
939 
941 
943  DLLEXPORT QoreStringMaker(const QoreEncoding* enc, const char* fmt, ...);
944 };
945 
947 
956 class TempString {
957 private:
958  QoreString* str;
959 
961  TempString(const TempString& );
962 
964  TempString& operator=(const TempString& );
965 
967  void* operator new(size_t);
968 
969 public:
971  DLLLOCAL TempString() : str(new QoreString) {
972  }
973 
975  DLLLOCAL TempString(const QoreEncoding* enc) : str(new QoreString(enc)) {
976  }
977 
979  DLLLOCAL TempString(QoreString* s) {
980  str = s;
981  }
982 
984  DLLLOCAL ~TempString() {
985  delete str;
986  }
987 
989  DLLLOCAL QoreString* operator->(){ return str; };
990 
992  DLLLOCAL QoreString* operator*() { return str; };
993 
995  DLLLOCAL operator bool() const { return str != 0; }
996 
998  DLLLOCAL QoreString* release() { QoreString* rv = str; str = 0; return rv; }
999 };
1000 
1002 
1015 private:
1016  QoreString* str;
1017  bool temp;
1018 
1020  DLLLOCAL TempEncodingHelper(const TempEncodingHelper& );
1021 
1023  DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper& );
1024 
1026  DLLLOCAL void* operator new(size_t);
1027 
1029  DLLLOCAL void discard_intern() {
1030  if (temp && str)
1031  delete str;
1032  }
1033 
1035 
1040  DLLLOCAL void set_intern(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1041  if (s->getEncoding() != qe) {
1042  str = s->convertEncoding(qe, xsink);
1043  temp = true;
1044  }
1045  else {
1046  str = const_cast<QoreString* >(s);
1047  temp = false;
1048  }
1049  }
1050 
1051 public:
1053 
1058  DLLLOCAL TempEncodingHelper(const QoreString& s, const QoreEncoding* qe, ExceptionSink* xsink) {
1059  set_intern(&s, qe, xsink);
1060  }
1061 
1063 
1068  DLLLOCAL TempEncodingHelper(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1069  set_intern(s, qe, xsink);
1070  }
1071 
1073  DLLLOCAL TempEncodingHelper() : str(0), temp(false) {
1074  }
1075 
1077  DLLLOCAL ~TempEncodingHelper() {
1078  discard_intern();
1079  }
1080 
1082 
1091  DLLLOCAL int set(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1092  discard_intern();
1093 
1094  set_intern(s, qe, xsink);
1095  return str != 0;
1096  }
1097 
1099  DLLLOCAL bool is_temp() const {
1100  return temp;
1101  }
1102 
1104  DLLLOCAL void makeTemp() {
1105  if (!temp && str) {
1106  str = new QoreString(*str);
1107  temp = true;
1108  }
1109  }
1110 
1112  DLLLOCAL const QoreString* operator->(){ return str; };
1113 
1115  DLLLOCAL const QoreString* operator*() { return str; };
1116 
1118 
1121  DLLLOCAL operator bool() const { return str != 0; }
1122 
1124 
1127  DLLLOCAL char* giveBuffer() {
1128  if (!str)
1129  return 0;
1130  if (temp)
1131  return str->giveBuffer();
1132  return strdup(str->getBuffer());
1133  }
1134 
1136 
1138  DLLEXPORT void removeBom();
1139 };
1140 
1141 #endif
DLLEXPORT const char * c_str() const
returns the string&#39;s buffer; this data should not be changed
DLLEXPORT void trim_trailing(const char *chars=0)
remove trailing whitespace or other characters
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 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 QoreString()
creates an empty string and assigns the default encoding QCS_DEFAULT
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 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:86
defines string encoding functions in Qore
Definition: QoreEncoding.h:85
DLLEXPORT BinaryNode * parseHex(ExceptionSink *xsink) const
parses the current string data as hexadecimal-encoded data and returns it as a BinaryNode pointer (ca...
DLLEXPORT QoreString * parseBase64ToString(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a QoreString pointer owned by...
DLLEXPORT bool empty() const
returns true if the string is empty, false if not
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 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 const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
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 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 unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned &len, ExceptionSink *xsink) const
return Unicode code point for the given byte offset
DLLEXPORT void trim_single_trailing(char c)
remove a single trailing character if present
DLLEXPORT qore_offset_t rfindAny(const char *str, qore_offset_t pos=-1) const
returns the last byte position of any of the given characters (bytes) within the string or -1 if not ...
DLLEXPORT void reserve(qore_size_t size)
ensures that at least the given size is available in the string; the string&#39;s contents are not affect...
DLLEXPORT void concatHex(const char *buf, qore_size_t size)
concatenates hexidecimal digits corresponding to the binary data passed up to byte "len" ...
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 QoreString * convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const
converts the encoding of the string to the specified encoding, returns 0 if an error occurs...
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 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 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:54
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 void concatISO8601DateTime(const DateTime *d)
concatenates a DateTime value to a string in the format YYYYMMDDTHH:mm:SS <- where the "T" is a liter...
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:74
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&#39;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 bool isDataAscii() const
returns true if the string is empty or has no characters with the high bit set (ie all characters < 1...
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char *str)
replaces bytes with the string passed
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
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...
#define CE_XHTML
code for encoding XHTML entities
Definition: QoreString.h:56
DLLEXPORT const char * getBuffer() const
returns the string&#39;s buffer; this data should not be changed
class used to hold a possibly temporary QoreString pointer, stack only, cannot be dynamically allocat...
Definition: QoreString.h:956
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
DLLLOCAL bool is_temp() const
returns true if a temporary string is being managed
Definition: QoreString.h:1099
DLLEXPORT void toupr()
converts the string to upper-case in place
DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset=0) const
return Unicode code point for character offset, string must be UTF-8
DLLEXPORT bool operator==(const QoreString &other) const
returns true if the other string is equal to this string (encodings also must be equal) ...
DLLLOCAL QoreString * release()
releases the QoreString pointer being managed and sets the internal pointer to 0
Definition: QoreString.h:998
DLLEXPORT void concatBase64(const char *buf, qore_size_t size)
concatenates the base64-encoded version of the binary data passed
DLLEXPORT qore_size_t strlen() const
returns number of bytes in the string (not including the null pointer)
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 equalPartialSoft(const QoreString &str, ExceptionSink *xsink) const
returns true if the beginning of the current string matches the argument string, false if not...
#define CD_ALL
code for decoding everything
Definition: QoreString.h:74
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1014
DLLEXPORT qore_offset_t findAny(const char *str, qore_offset_t pos=0) const
returns the byte position of any of the given characters (bytes) within the string or -1 if not found...
DLLLOCAL bool operator!=(const QoreString &other) const
returns true if the other string is not equal to this string (encodings also must be equal) ...
Definition: QoreString.h:823
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...
DLLEXPORT int concatDecode(ExceptionSink *xsink, const QoreString &str, unsigned code=CD_ALL)
concatenates a string and decodes HTML, XML, and numeric character references as per the supplied arg...
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
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
DLLLOCAL const QoreString * operator*()
returns the string being managed
Definition: QoreString.h:1115
DLLLOCAL ~TempString()
deletes the QoreString pointer being managed
Definition: QoreString.h:984
DLLEXPORT bool equalPartial(const QoreString &str) const
returns true if the beginning of the current string matches the argument string, false if not...
DLLEXPORT int concatEncode(ExceptionSink *xsink, const QoreString &str, unsigned code=CE_XHTML)
concatenates a string and encodes it according to the encoding argument passed
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
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:241
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
DLLEXPORT qore_size_t capacity() const
returns number of bytes allocated for the string&#39;s buffer, capacity is always >= size ...
DLLLOCAL void makeTemp()
ensures that the object is holding a temporary value
Definition: QoreString.h:1104
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:1073
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:77
DLLLOCAL ~TempEncodingHelper()
deletes any temporary string being managed by the object
Definition: QoreString.h:1077
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:989
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 int trimTrailing(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes trailing whitespace or other characters
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...
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 bool equal(const QoreString &str) const
returns true if the strings are equal, false if not, if the character encodings are different...
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...
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 int64 toBigInt() const
returns the value of the string as an int64
DLLEXPORT void allocate(unsigned requested_size)
Ensure the internal buffer has at least expected size in bytes.
DLLEXPORT int trimLeading(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes leading whitespace or other characters
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding for the string
DLLEXPORT bool isDataPrintableAscii() const
returns true if the string is empty or only contains printable non-control ASCII characters (ie all c...
DLLEXPORT int compareSoft(const QoreString *str, ExceptionSink *xsink) const
compares the string with another string, performing character set encoding conversion if necessary ...
DLLLOCAL char * giveBuffer()
returns a char pointer of the string, the caller owns the pointer returned (it must be manually freed...
Definition: QoreString.h:1127
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 ...
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 void removeBom()
remove any leading byte order marker (BOM) from UTF-16* strings
DLLLOCAL QoreString * operator*()
returns the QoreString pointer being managed
Definition: QoreString.h:992
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
DLLEXPORT qore_size_t size() const
returns number of bytes in the string (not including the null pointer)
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 int compare(const QoreString *str) const
compares two strings without converting encodings (if the encodings do not match then "this" is deeme...
DLLLOCAL const QoreString * operator->()
returns the string being managed
Definition: QoreString.h:1112
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:971
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 qore_size_t length() const
returns the number of characters (not bytes) in the string
DLLEXPORT QoreString * reverse() const
return a Qorestring with the characters reversed