Qore Programming Language  0.9.3.2
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 - 2018 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 <cstdarg>
39 #include <string>
40 
41 class DateTime;
42 class BinaryNode;
43 
45 
48 #define CE_HTML (1 << 0)
50 #define CE_XML (1 << 1)
52 #define CE_NONASCII (1 << 2)
54 #define CE_XHTML (CE_HTML | CE_XML)
56 #define CE_ALL (CE_XHTML | CE_NONASCII)
58 
59 
61 
64 #define CD_HTML (1 << 0)
66 #define CD_XML (1 << 1)
68 #define CD_NUM_REF (1 << 2)
70 #define CD_XHTML (CD_HTML | CD_XML)
72 #define CD_ALL (CD_XHTML | CD_NUM_REF)
74 
75 
77 
81 class QoreString {
82  friend hashdecl qore_string_private;
83 protected:
85  hashdecl qore_string_private* priv = nullptr;
86 
87  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, QoreString* extract = 0);
88  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char* str, qore_size_t str_len, QoreString* extract = 0);
89  DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink* xsink, QoreString* extract = 0);
90  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink, QoreString* extract = 0);
91  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString* str, ExceptionSink* xsink, QoreString* extract = 0);
92  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset) const;
93  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset, qore_offset_t length) const;
94  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, ExceptionSink* xsink) const;
95  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
96 
97  // writes a new QoreString with the characters reversed of the "this" QoreString
98  // assumes the encoding is the same and the length is 0
99  DLLLOCAL void concat_reverse(QoreString* targ) const;
100 
101  DLLLOCAL int snprintf(size_t size, const char* fmt, ...);
102  DLLLOCAL int vsnprintf(size_t size, const char* fmt, va_list args);
103 
104 public:
106  DLLEXPORT QoreString();
107 
109  DLLEXPORT QoreString(bool b);
110 
112  DLLEXPORT QoreString(const char* str);
113 
115  DLLEXPORT QoreString(const char* str, const QoreEncoding* new_qorecharset);
116 
118  DLLEXPORT QoreString(const QoreEncoding* new_qorecharset);
119 
121  DLLEXPORT QoreString(const char* str, qore_size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
122 
124  DLLEXPORT QoreString(const std::string& str, const QoreEncoding* new_encoding = QCS_DEFAULT);
125 
127  DLLEXPORT QoreString(char c);
128 
130  DLLEXPORT QoreString(const QoreString& str);
131 
133  DLLEXPORT QoreString(const QoreString* str);
134 
136  DLLEXPORT QoreString(const QoreString* str, qore_size_t len);
137 
139  DLLEXPORT QoreString(int64 i);
140 
142  DLLEXPORT QoreString(double f);
143 
145  DLLEXPORT QoreString(const DateTime* date);
146 
148  DLLEXPORT QoreString(const BinaryNode* bin);
149 
151  DLLEXPORT QoreString(const BinaryNode* bin, qore_size_t maxlinelen);
152 
154  DLLEXPORT QoreString(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
155 
157  DLLEXPORT ~QoreString();
158 
160 
162  DLLEXPORT qore_size_t length() const;
163 
165  DLLEXPORT void set(const char* str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
166 
168  DLLEXPORT void set(const std::string& str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
169 
171  DLLEXPORT void set(const QoreString* str);
172 
174  DLLEXPORT void set(const QoreString& str);
175 
177  DLLEXPORT void set(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
178 
180  DLLEXPORT void setEncoding(const QoreEncoding* new_encoding);
181 
183 
193  DLLEXPORT int concatEncode(ExceptionSink* xsink, const QoreString& str, unsigned code = CE_XHTML);
194 
196 
208  DLLEXPORT int concatDecode(ExceptionSink* xsink, const QoreString& str, unsigned code = CD_ALL);
209 
211 
214  DLLEXPORT void concatAndHTMLEncode(const char* str);
215 
217 
220  DLLEXPORT void concatAndHTMLDecode(const QoreString* str);
221 
223 
226  DLLEXPORT void concatAndHTMLDecode(const char* str, size_t slen);
227 
229 
232  DLLEXPORT void concatAndHTMLDecode(const char* str);
233 
235 
237  DLLEXPORT void concatDecodeUrl(const char* url);
238 
240  DLLEXPORT int concatDecodeUrl(const QoreString& url, ExceptionSink* xsink);
241 
243 
247  DLLEXPORT int concatEncodeUrl(ExceptionSink* xsink, const QoreString& url, bool encode_all = false);
248 
250 
253  DLLEXPORT int concatDecodeUriRequest(const QoreString& url, ExceptionSink* xsink);
254 
256 
261  DLLEXPORT int concatEncodeUriRequest(ExceptionSink* xsink, const QoreString& url);
262 
264  DLLEXPORT void concatEscape(const QoreString* str, char c, char esc_char, ExceptionSink* xsink);
265 
267  DLLEXPORT void concatEscape(const char* str, char c, char esc_char = '\\');
268 
270 
276  DLLEXPORT void concatAndHTMLEncode(const QoreString* str, ExceptionSink* xsink);
277 
279  DLLEXPORT void concat(const QoreString* str, ExceptionSink* xsink);
280 
282 
288  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, ExceptionSink* xsink);
289 
291 
298  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, qore_offset_t len, ExceptionSink* xsink);
299 
301 
306  DLLEXPORT void concat(const QoreString* str, qore_size_t size, ExceptionSink* xsink);
307 
309  DLLEXPORT void concatBase64(const char* buf, qore_size_t size);
310 
312  DLLEXPORT void concatBase64(const BinaryNode* bin);
313 
315  DLLEXPORT void concatBase64(const QoreString* str);
316 
318  DLLEXPORT void concatBase64(const char* buf, qore_size_t size, qore_size_t maxlinelen);
319 
321  DLLEXPORT void concatBase64(const BinaryNode* bin, qore_size_t maxlinelen);
322 
324  DLLEXPORT void concatBase64(const QoreString* str, qore_size_t maxlinelen);
325 
327 
331  DLLEXPORT BinaryNode* parseBase64(ExceptionSink* xsink) const;
332 
334 
338  DLLEXPORT QoreString* parseBase64ToString(ExceptionSink* xsink) const;
339 
341 
346  DLLEXPORT QoreString* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
347 
349 
351  DLLEXPORT void concatHex(const char* buf, qore_size_t size);
352 
354  DLLEXPORT void concatHex(const BinaryNode* bin);
355 
357  DLLEXPORT void concatHex(const QoreString* str);
358 
360 
364  DLLEXPORT BinaryNode* parseHex(ExceptionSink* xsink) const;
365 
367  DLLEXPORT void concat(const DateTime* d);
368 
370  DLLEXPORT void concatISO8601DateTime(const DateTime* d);
371 
373  DLLEXPORT void concat(const char* str);
374 
376  DLLEXPORT void concat(const std::string& str);
377 
379  DLLEXPORT void concat(const char* str, qore_size_t size);
380 
382  DLLEXPORT void concat(const char c);
383 
385 
390  DLLEXPORT int compareSoft(const QoreString* str, ExceptionSink* xsink) const;
391 
393 
397  DLLEXPORT int compare(const QoreString* str) const;
398 
400 
404  DLLEXPORT int compare(const char* str) const;
405 
407 
409  DLLEXPORT bool equal(const QoreString& str) const;
410 
412 
414  DLLEXPORT bool equal(const char* str) const;
415 
417 
423  DLLEXPORT bool equalSoft(const QoreString& str, ExceptionSink* xsink) const;
424 
426 
428  DLLEXPORT bool equalPartial(const QoreString& str) const;
429 
431 
433  DLLEXPORT bool equalPartial(const char* str) const;
434 
436 
442  DLLEXPORT bool equalPartialSoft(const QoreString& str, ExceptionSink* xsink) const;
443 
445 
451  DLLEXPORT bool equalPartialPath(const QoreString& str, ExceptionSink* xsink) const;
452 
454  DLLEXPORT void terminate(qore_size_t size);
455 
457 
459  DLLEXPORT void reserve(qore_size_t size);
460 
462 
464  DLLEXPORT int sprintf(const char* fmt, ...);
465 
467 
469  DLLEXPORT int vsprintf(const char* fmt, va_list args);
470 
472 
474  DLLEXPORT void take(char* str);
475 
477  DLLEXPORT void take(char* str, const QoreEncoding* enc);
479 
480  DLLEXPORT void take(char* str, qore_size_t size);
481 
483  DLLEXPORT void take(char* str, qore_size_t size, const QoreEncoding* enc);
484 
486  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size);
487 
489  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size, const QoreEncoding* enc);
490 
492 
497  DLLEXPORT QoreString* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
498 
500 
503  DLLEXPORT char* giveBuffer();
504 
506  DLLEXPORT void clear();
507 
509 
511  DLLEXPORT void reset();
512 
514 
516  DLLEXPORT void replaceAll(const char* old_str, const char* new_str);
517 
519 
521  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char* str);
522 
524 
529  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str);
530 
532 
534  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str, ExceptionSink* xsink);
535 
537 
539  DLLEXPORT void replaceChar(qore_size_t offset, char c);
540 
542 
546  DLLEXPORT void splice(qore_offset_t offset, ExceptionSink* xsink);
547 
549 
554  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
555 
557 
563  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink* xsink);
564 
566 
572  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString& str, ExceptionSink* xsink);
573 
575 
580  DLLEXPORT QoreString* extract(qore_offset_t offset, ExceptionSink* xsink);
581 
583 
590 
592 
599  DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink* xsink);
600 
602 
607  DLLEXPORT QoreString* substr(qore_offset_t offset, ExceptionSink* xsink) const;
608 
610 
616  DLLEXPORT QoreString* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
617 
619  DLLEXPORT qore_size_t chomp();
620 
622  DLLEXPORT const QoreEncoding* getEncoding() const;
623 
625  DLLEXPORT QoreString* copy() const;
626 
628 
630  DLLEXPORT void tolwr();
631 
633 
635  DLLEXPORT void toupr();
636 
638  DLLEXPORT qore_size_t strlen() const;
639 
641  DLLEXPORT qore_size_t size() const;
642 
644  DLLEXPORT qore_size_t capacity() const;
645 
647  DLLEXPORT const char* getBuffer() const;
648 
650  DLLEXPORT const char* c_str() const;
651 
653 
655  DLLEXPORT void allocate(unsigned requested_size);
656 
658 
664  DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times);
665 
667 
672  DLLEXPORT int insert(const char* str, qore_size_t pos);
673 
675  DLLEXPORT void addch(char c, unsigned times);
676 
678 
684  DLLEXPORT void concatUTF8FromUnicode(unsigned code);
685 
687 
691  DLLEXPORT int concatUnicode(unsigned code, ExceptionSink* xsink);
692 
694 
698  DLLEXPORT int concatUnicode(unsigned code);
699 
701 
704  DLLEXPORT QoreString* reverse() const;
705 
707 
709  DLLEXPORT void trim_trailing(const char* chars = 0);
710 
712 
714  DLLEXPORT void trim_leading(const char* chars = 0);
715 
717 
719  DLLEXPORT void trim(const char* chars = 0);
720 
722 
724  DLLEXPORT void trim_trailing(char c);
725 
727 
729  DLLEXPORT void trim_single_trailing(char c);
730 
732 
734  DLLEXPORT void trim_leading(char c);
735 
737 
739  DLLEXPORT void trim_single_leading(char c);
740 
742 
744  DLLEXPORT void trim(char c);
745 
747 
753  DLLEXPORT int trim(ExceptionSink* xsink, const QoreString* chars = nullptr);
754 
756 
762  DLLEXPORT int trimLeading(ExceptionSink* xsink, const QoreString* chars = nullptr);
763 
765 
771  DLLEXPORT int trimTrailing(ExceptionSink* xsink, const QoreString* chars = nullptr);
772 
774 
778  DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
779 
781 
786  DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink* xsink) const;
787 
789 
797  DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned& len, ExceptionSink* xsink) const;
798 
800  DLLEXPORT void prepend(const char* str);
801 
803  DLLEXPORT void prepend(const char* str, qore_size_t size);
804 
806  DLLEXPORT QoreString& operator=(const QoreString& other);
807 
809  DLLEXPORT QoreString& operator=(const char* other);
810 
812  DLLEXPORT QoreString& operator=(const std::string& other);
813 
815  DLLEXPORT bool operator==(const QoreString& other) const;
816 
818  DLLEXPORT bool operator==(const std::string& other) const;
819 
821  DLLEXPORT bool operator==(const char* other) const;
822 
824  DLLLOCAL bool operator!=(const QoreString& other) const {
825  return !(*this == other);
826  }
827 
829  DLLLOCAL bool operator!=(const std::string& other) const {
830  return !(*this == other);
831  }
832 
834  DLLLOCAL bool operator!=(const char* other) const {
835  return !(*this == other);
836  }
837 
839 
844  DLLEXPORT char operator[](qore_offset_t pos) const;
845 
847  DLLEXPORT QoreString& operator+=(const char* str);
848 
850  DLLEXPORT QoreString& operator+=(const std::string& str);
851 
853  DLLEXPORT bool empty() const;
854 
856  DLLEXPORT qore_offset_t index(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
857 
859  DLLEXPORT qore_offset_t bindex(const QoreString& needle, qore_offset_t pos) const;
860 
862  DLLEXPORT qore_offset_t bindex(const char* needle, qore_offset_t pos) const;
863 
865  DLLEXPORT qore_offset_t bindex(const std::string& needle, qore_offset_t pos) const;
866 
868 
874  DLLEXPORT qore_offset_t rindex(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
875 
877  DLLEXPORT qore_offset_t brindex(const QoreString& needle, qore_offset_t pos) const;
878 
880  DLLEXPORT qore_offset_t brindex(const char* needle, qore_offset_t pos) const;
881 
883  DLLEXPORT qore_offset_t brindex(const std::string& needle, qore_offset_t pos) const;
884 
886  DLLEXPORT qore_offset_t find(char c, qore_offset_t pos = 0) const;
887 
889  DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos = -1) const;
890 
892  DLLEXPORT qore_offset_t findAny(const char *str, qore_offset_t pos = 0) const;
893 
895  DLLEXPORT qore_offset_t rfindAny(const char *str, qore_offset_t pos = -1) const;
896 
898 
900  DLLEXPORT bool isDataPrintableAscii() const;
901 
903 
905  DLLEXPORT bool isDataAscii() const;
906 
908  DLLEXPORT int64 toBigInt() const;
909 
911 
916  DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink* xsink) const;
917 
918  // concatenates a qorestring without converting encodings - internal only
919  DLLLOCAL void concat(const QoreString* str);
920 
921  // private constructor
922  DLLLOCAL QoreString(struct qore_string_private* p);
923 };
924 
925 DLLEXPORT QoreString* checkEncoding(const QoreString* str, const QoreEncoding* enc, ExceptionSink* xsink);
926 
927 class QoreStringMaker : public QoreString {
928 private:
930  DLLLOCAL QoreStringMaker(const QoreStringMaker& str);
931 
933  DLLLOCAL QoreStringMaker& operator=(const QoreStringMaker&);
934 
935 public:
937 
939  DLLEXPORT QoreStringMaker(const char* fmt, ...);
940 
942 
944  DLLEXPORT QoreStringMaker(const QoreEncoding* enc, const char* fmt, ...);
945 };
946 
948 
957 class TempString {
958 private:
959  QoreString* str;
960 
962  TempString(const TempString& );
963 
965  TempString& operator=(const TempString& );
966 
968  void* operator new(size_t);
969 
970 public:
972  DLLLOCAL TempString() : str(new QoreString) {
973  }
974 
976  DLLLOCAL TempString(const QoreEncoding* enc) : str(new QoreString(enc)) {
977  }
978 
980  DLLLOCAL TempString(QoreString* s) {
981  str = s;
982  }
983 
985  DLLLOCAL ~TempString() {
986  delete str;
987  }
988 
990  DLLLOCAL QoreString* operator->(){ return str; };
991 
993  DLLLOCAL QoreString* operator*() { return str; };
994 
996  DLLLOCAL operator bool() const { return str != 0; }
997 
999  DLLLOCAL QoreString* release() { QoreString* rv = str; str = 0; return rv; }
1000 };
1001 
1003 
1016 private:
1017  QoreString* str;
1018  bool temp;
1019 
1021  DLLLOCAL TempEncodingHelper(const TempEncodingHelper& );
1022 
1024  DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper& );
1025 
1027  DLLLOCAL void* operator new(size_t);
1028 
1030  DLLLOCAL void discard_intern() {
1031  if (temp && str)
1032  delete str;
1033  }
1034 
1036 
1041  DLLLOCAL void set_intern(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1042  if (s->getEncoding() != qe) {
1043  str = s->convertEncoding(qe, xsink);
1044  temp = true;
1045  }
1046  else {
1047  str = const_cast<QoreString* >(s);
1048  temp = false;
1049  }
1050  }
1051 
1052 public:
1054 
1059  DLLLOCAL TempEncodingHelper(const QoreString& s, const QoreEncoding* qe, ExceptionSink* xsink) {
1060  set_intern(&s, qe, xsink);
1061  }
1062 
1064 
1069  DLLLOCAL TempEncodingHelper(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1070  set_intern(s, qe, xsink);
1071  }
1072 
1074  DLLLOCAL TempEncodingHelper() : str(0), temp(false) {
1075  }
1076 
1078  DLLLOCAL ~TempEncodingHelper() {
1079  discard_intern();
1080  }
1081 
1083 
1092  DLLLOCAL int set(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1093  discard_intern();
1094 
1095  set_intern(s, qe, xsink);
1096  return str != 0;
1097  }
1098 
1100  DLLLOCAL bool is_temp() const {
1101  return temp;
1102  }
1103 
1105  DLLLOCAL void makeTemp() {
1106  if (!temp && str) {
1107  str = new QoreString(*str);
1108  temp = true;
1109  }
1110  }
1111 
1113  DLLLOCAL const QoreString* operator->(){ return str; };
1114 
1116  DLLLOCAL const QoreString* operator*() { return str; };
1117 
1119 
1122  DLLLOCAL operator bool() const { return str != 0; }
1123 
1125 
1128  DLLLOCAL char* giveBuffer() {
1129  if (!str)
1130  return 0;
1131  if (temp)
1132  return str->giveBuffer();
1133  return strdup(str->getBuffer());
1134  }
1135 
1137 
1139  DLLEXPORT void removeBom();
1140 };
1141 
1142 #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...
hashdecl qore_string_private * priv
the private implementation of QoreString
Definition: QoreString.h:85
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
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...
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:73
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:81
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:55
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:957
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 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) ...
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:73
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1015
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:824
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...
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
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:46
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:260
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 ...
DLLEXPORT void terminate(qore_size_t size)
terminates the string at byte position "size", the string is reallocated if necessary ...
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
DLLEXPORT void trim(const char *chars=0)
remove leading and trailing whitespace or other characters
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 ...
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 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...
DLLEXPORT void take(char *str)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
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