| Qore Programming Language - C/C++ Library 1.0.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 - 2021 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 struct qore_string_private;
83
84 public:
86 DLLEXPORT QoreString();
87
89 DLLEXPORT QoreString(bool b);
90
92 DLLEXPORT QoreString(const char* str);
93
95 DLLEXPORT QoreString(const char* str, const QoreEncoding* new_qorecharset);
96
98 DLLEXPORT QoreString(const QoreEncoding* new_qorecharset);
99
101 DLLEXPORT QoreString(const char* str, size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
102
104 DLLEXPORT QoreString(const std::string& str, const QoreEncoding* new_encoding = QCS_DEFAULT);
105
107 DLLEXPORT QoreString(char c);
108
110 DLLEXPORT QoreString(const QoreString& str);
111
113 DLLEXPORT QoreString(const QoreString* str);
114
116 DLLEXPORT QoreString(const QoreString* str, size_t len);
117
119 DLLEXPORT QoreString(int64 i);
120
122 DLLEXPORT QoreString(double f);
123
125 DLLEXPORT QoreString(const DateTime* date);
126
128 DLLEXPORT QoreString(const BinaryNode* bin);
129
131 DLLEXPORT QoreString(const BinaryNode* bin, size_t maxlinelen);
132
134 DLLEXPORT QoreString(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
135
137 DLLEXPORT ~QoreString();
138
140
142 DLLEXPORT size_t length() const;
143
145 DLLEXPORT void set(const char* str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
146
148
150 DLLEXPORT void set(const char* str, size_t len);
151
153 DLLEXPORT void set(const std::string& str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
154
156 DLLEXPORT void set(const QoreString* str);
157
159 DLLEXPORT void set(const QoreString& str);
160
162 DLLEXPORT void set(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
163
165 DLLEXPORT void setEncoding(const QoreEncoding* new_encoding);
166
168
178 DLLEXPORT int concatEncode(ExceptionSink* xsink, const QoreString& str, unsigned code = CE_XHTML);
179
181
193 DLLEXPORT int concatDecode(ExceptionSink* xsink, const QoreString& str, unsigned code = CD_ALL);
194
196
199 DLLEXPORT void concatAndHTMLEncode(const char* str);
200
202
205 DLLEXPORT void concatAndHTMLDecode(const QoreString* str);
206
208
211 DLLEXPORT void concatAndHTMLDecode(const char* str, size_t slen);
212
214
217 DLLEXPORT void concatAndHTMLDecode(const char* str);
218
220
222 DLLEXPORT void concatDecodeUrl(const char* url);
223
225 DLLEXPORT int concatDecodeUrl(const QoreString& url, ExceptionSink* xsink);
226
228
232 DLLEXPORT int concatEncodeUrl(ExceptionSink* xsink, const QoreString& url, bool encode_all = false);
233
235
238 DLLEXPORT int concatDecodeUriRequest(const QoreString& url, ExceptionSink* xsink);
239
241
246 DLLEXPORT int concatEncodeUriRequest(ExceptionSink* xsink, const QoreString& url);
247
249 DLLEXPORT void concatEscape(const QoreString* str, char c, char esc_char, ExceptionSink* xsink);
250
252 DLLEXPORT void concatEscape(const char* str, char c, char esc_char = '\\');
253
255
261 DLLEXPORT void concatAndHTMLEncode(const QoreString* str, ExceptionSink* xsink);
262
264 DLLEXPORT void concat(const QoreString* str, ExceptionSink* xsink);
265
267
273 DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, ExceptionSink* xsink);
274
276
283 DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, qore_offset_t len, ExceptionSink* xsink);
284
286
291 DLLEXPORT void concat(const QoreString* str, size_t size, ExceptionSink* xsink);
292
294 DLLEXPORT void concatBase64(const char* buf, size_t size);
295
297 DLLEXPORT void concatBase64(const BinaryNode* bin);
298
300 DLLEXPORT void concatBase64(const QoreString* str);
301
303 DLLEXPORT void concatBase64(const char* buf, size_t size, size_t maxlinelen);
304
306 DLLEXPORT void concatBase64(const BinaryNode* bin, size_t maxlinelen);
307
309 DLLEXPORT void concatBase64(const QoreString* str, size_t maxlinelen);
310
312
316 DLLEXPORT BinaryNode* parseBase64(ExceptionSink* xsink) const;
317
319
323 DLLEXPORT QoreString* parseBase64ToString(ExceptionSink* xsink) const;
324
326
331 DLLEXPORT QoreString* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
332
334
336 DLLEXPORT void concatHex(const char* buf, size_t size);
337
339 DLLEXPORT void concatHex(const BinaryNode* bin);
340
342 DLLEXPORT void concatHex(const QoreString* str);
343
345
349 DLLEXPORT BinaryNode* parseHex(ExceptionSink* xsink) const;
350
352 DLLEXPORT void concat(const DateTime* d);
353
355 DLLEXPORT void concatISO8601DateTime(const DateTime* d);
356
358 DLLEXPORT void concat(const char* str);
359
361 DLLEXPORT void concat(const std::string& str);
362
364 DLLEXPORT void concat(const char* str, size_t size);
365
367 DLLEXPORT void concat(const char c);
368
370
375 DLLEXPORT int compareSoft(const QoreString* str, ExceptionSink* xsink) const;
376
378
382 DLLEXPORT int compare(const QoreString* str) const;
383
385
389 DLLEXPORT int compare(const char* str) const;
390
392
394 DLLEXPORT bool equal(const QoreString& str) const;
395
397
399 DLLEXPORT bool equal(const char* str) const;
400
402
408 DLLEXPORT bool equalSoft(const QoreString& str, ExceptionSink* xsink) const;
409
411
413 DLLEXPORT bool equalPartial(const QoreString& str) const;
414
416
418 DLLEXPORT bool equalPartial(const char* str) const;
419
421
427 DLLEXPORT bool equalPartialSoft(const QoreString& str, ExceptionSink* xsink) const;
428
430
436 DLLEXPORT bool equalPartialPath(const QoreString& str, ExceptionSink* xsink) const;
437
439
441 DLLEXPORT bool startsWith(const char* str) const;
442
444
446 DLLEXPORT bool startsWith(const std::string& str) const;
447
449
451 DLLEXPORT bool endsWith(const char* str) const;
452
454
456 DLLEXPORT bool endsWith(const std::string& str) const;
457
459 DLLEXPORT void terminate(size_t size);
460
462
464 DLLEXPORT void reserve(size_t size);
465
467
469 DLLEXPORT int sprintf(const char* fmt, ...);
470
472
474 DLLEXPORT int vsprintf(const char* fmt, va_list args);
475
477
479 DLLEXPORT void take(char* str);
480
482 DLLEXPORT void take(char* str, const QoreEncoding* enc);
484
485 DLLEXPORT void take(char* str, size_t size);
486
488 DLLEXPORT void take(char* str, size_t size, const QoreEncoding* enc);
489
491 DLLEXPORT void takeAndTerminate(char* str, size_t size);
492
494 DLLEXPORT void takeAndTerminate(char* str, size_t size, const QoreEncoding* enc);
495
497
502 DLLEXPORT QoreString* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
503
505
508 DLLEXPORT char* giveBuffer();
509
511 DLLEXPORT void clear();
512
514
516 DLLEXPORT void reset();
517
519
521 DLLEXPORT void replaceAll(const char* old_str, const char* new_str);
522
524
526 DLLEXPORT void replace(size_t offset, size_t len, const char* str);
527
529
531 DLLEXPORT void replace(size_t offset, size_t len, const QoreString* str, ExceptionSink* xsink);
532
534
536 DLLEXPORT void replaceChar(size_t offset, char c);
537
539
543 DLLEXPORT void splice(qore_offset_t offset, ExceptionSink* xsink);
544
546
551 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
552
554
560 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink* xsink);
561
563
569 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString& str, ExceptionSink* xsink);
570
572
577 DLLEXPORT QoreString* extract(qore_offset_t offset, ExceptionSink* xsink);
578
580
586 DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
587
589
596 DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink* xsink);
597
599
604 DLLEXPORT QoreString* substr(qore_offset_t offset, ExceptionSink* xsink) const;
605
607
613 DLLEXPORT QoreString* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
614
616 DLLEXPORT size_t chomp();
617
619 DLLEXPORT const QoreEncoding* getEncoding() const;
620
622 DLLEXPORT QoreString* copy() const;
623
625
627 DLLEXPORT void tolwr();
628
630
632 DLLEXPORT void toupr();
633
635 DLLEXPORT size_t strlen() const;
636
638 DLLEXPORT size_t size() const;
639
641 DLLEXPORT size_t capacity() const;
642
644 DLLEXPORT const char* getBuffer() const;
645
647 DLLEXPORT const char* c_str() const;
648
650
652 DLLEXPORT void allocate(unsigned requested_size);
653
655
661 DLLEXPORT int insertch(char c, size_t pos, unsigned times);
662
664
669 DLLEXPORT int insert(const char* str, size_t pos);
670
672 DLLEXPORT void addch(char c, unsigned times);
673
675
681 DLLEXPORT void concatUTF8FromUnicode(unsigned code);
682
684
688 DLLEXPORT int concatUnicode(unsigned code, ExceptionSink* xsink);
689
691
695 DLLEXPORT int concatUnicode(unsigned code);
696
698
701 DLLEXPORT QoreString* reverse() const;
702
704
706 DLLEXPORT void trim_trailing(const char* chars = 0);
707
709
711 DLLEXPORT void trim_leading(const char* chars = 0);
712
714
716 DLLEXPORT void trim(const char* chars = 0);
717
719
721 DLLEXPORT void trim_trailing(char c);
722
724
726 DLLEXPORT void trim_single_trailing(char c);
727
729
731 DLLEXPORT void trim_leading(char c);
732
734
736 DLLEXPORT void trim_single_leading(char c);
737
739
741 DLLEXPORT void trim(char c);
742
744
750 DLLEXPORT int trim(ExceptionSink* xsink, const QoreString* chars = nullptr);
751
753
759 DLLEXPORT int trimLeading(ExceptionSink* xsink, const QoreString* chars = nullptr);
760
762
768 DLLEXPORT int trimTrailing(ExceptionSink* xsink, const QoreString* chars = nullptr);
769
771
775 DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
776
778
783 DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink* xsink) const;
784
786
794 DLLEXPORT unsigned int getUnicodePointFromBytePos(size_t offset, unsigned& len, ExceptionSink* xsink) const;
795
797 DLLEXPORT void prepend(const char* str);
798
800 DLLEXPORT void prepend(const char* str, size_t size);
801
803 DLLEXPORT QoreString& operator=(const QoreString& other);
804
806 DLLEXPORT QoreString& operator=(const char* other);
807
809 DLLEXPORT QoreString& operator=(const std::string& other);
810
812 DLLEXPORT bool operator==(const QoreString& other) const;
813
815 DLLEXPORT bool operator==(const std::string& other) const;
816
818 DLLEXPORT bool operator==(const char* other) const;
819
821 DLLLOCAL bool operator!=(const QoreString& other) const {
822 return !(*this == other);
823 }
824
826 DLLLOCAL bool operator!=(const std::string& other) const {
827 return !(*this == other);
828 }
829
831 DLLLOCAL bool operator!=(const char* other) const {
832 return !(*this == other);
833 }
834
836
840 DLLEXPORT int operator[](qore_offset_t pos) const;
841
843 DLLEXPORT QoreString& operator+=(const char* str);
844
846 DLLEXPORT QoreString& operator+=(const std::string& str);
847
849 DLLEXPORT bool empty() const;
850
852 DLLEXPORT qore_offset_t index(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
853
855 DLLEXPORT qore_offset_t bindex(const QoreString& needle, qore_offset_t pos = 0) const;
856
858 DLLEXPORT qore_offset_t bindex(const char* needle, qore_offset_t pos = 0) const;
859
861 DLLEXPORT qore_offset_t bindex(const std::string& needle, qore_offset_t pos = 0) const;
862
864
870 DLLEXPORT qore_offset_t rindex(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
871
873 DLLEXPORT qore_offset_t brindex(const QoreString& needle, qore_offset_t pos = -1) const;
874
876 DLLEXPORT qore_offset_t brindex(const char* needle, qore_offset_t pos = -1) const;
877
879 DLLEXPORT qore_offset_t brindex(const std::string& needle, qore_offset_t pos = -1) const;
880
882 DLLEXPORT qore_offset_t find(char c, qore_offset_t pos = 0) const;
883
885 DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos = -1) const;
886
888
890 DLLEXPORT qore_offset_t find(const char* str, qore_offset_t pos = 0) const;
891
893
895 DLLEXPORT qore_offset_t rfind(const char* str, qore_offset_t pos = -1) const;
896
898
900 DLLEXPORT qore_offset_t find(const std::string& str, qore_offset_t pos = 0) const;
901
903
905 DLLEXPORT qore_offset_t rfind(const std::string& str, qore_offset_t pos = -1) const;
906
908 DLLEXPORT qore_offset_t findAny(const char *str, qore_offset_t pos = 0) const;
909
911 DLLEXPORT qore_offset_t rfindAny(const char *str, qore_offset_t pos = -1) const;
912
914
916 DLLEXPORT bool isDataPrintableAscii() const;
917
919
921 DLLEXPORT bool isDataAscii() const;
922
924 DLLEXPORT int64 toBigInt() const;
925
927
935 DLLEXPORT size_t getCharWidth(ExceptionSink* xsink) const;
936
938
943 DLLEXPORT qore_offset_t getByteOffset(size_t i, ExceptionSink* xsink) const;
944
945 // concatenates a qorestring without converting encodings - internal only
946 DLLLOCAL void concat(const QoreString* str);
947
948 // private constructor
949 DLLLOCAL QoreString(struct qore_string_private* p);
950
951 protected:
953 struct qore_string_private* priv = nullptr;
954
955 // writes a new QoreString with the characters reversed of the "this" QoreString
956 // assumes the encoding is the same and the length is 0
957 DLLLOCAL void concat_reverse(QoreString* targ) const;
958
959 DLLLOCAL int snprintf(size_t size, const char* fmt, ...);
960 DLLLOCAL int vsnprintf(size_t size, const char* fmt, va_list args);
961 };
962
963 DLLEXPORT QoreString* checkEncoding(const QoreString* str, const QoreEncoding* enc, ExceptionSink* xsink);
964
965 class QoreStringMaker : public QoreString {
966 public:
968
970 DLLEXPORT QoreStringMaker(const char* fmt, ...);
971
973
975 DLLEXPORT QoreStringMaker(const QoreEncoding* enc, const char* fmt, ...);
976
977 private:
978 DLLLOCAL QoreStringMaker(const QoreStringMaker& str) = delete;
979 DLLLOCAL QoreStringMaker& operator=(const QoreStringMaker&) = delete;
980 };
981
983
992 class TempString {
993 public:
995 DLLLOCAL TempString() : str(new QoreString) {
996 }
997
999 DLLLOCAL TempString(const QoreEncoding* enc) : str(new QoreString(enc)) {
1000 }
1001
1003 DLLLOCAL TempString(QoreString* s) {
1004 str = s;
1005 }
1006
1008 DLLLOCAL ~TempString() {
1009 delete str;
1010 }
1011
1013 DLLLOCAL QoreString* operator->(){ return str; };
1014
1016 DLLLOCAL QoreString* operator*() { return str; };
1017
1019 DLLLOCAL operator bool() const { return str != nullptr; }
1020
1022 DLLLOCAL QoreString* release() {
1023 QoreString* rv = str;
1024 str = nullptr;
1025 return rv;
1026 }
1027
1028 private:
1029 QoreString* str;
1030
1031 TempString(const TempString&) = delete;
1032 TempString& operator=(const TempString&) = delete;
1033 void* operator new(size_t) = delete;
1034 };
1035
1037
1051 class TempEncodingHelper {
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() {
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 != nullptr;
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 nullptr;
1131 if (temp)
1132 return str->giveBuffer();
1133 return strdup(str->getBuffer());
1134 }
1135
1137
1139 DLLEXPORT void removeBom();
1140
1141 private:
1142 QoreString* str = nullptr;
1143 bool temp = false;
1144
1145 DLLLOCAL TempEncodingHelper(const TempEncodingHelper&) = delete;
1146 DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper&) = delete;
1147 DLLLOCAL void* operator new(size_t) = delete;
1148
1150 DLLLOCAL void discard_intern() {
1151 if (temp && str)
1152 delete str;
1153 }
1154
1156
1161 DLLLOCAL void set_intern(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1162 if (s->getEncoding() != qe) {
1163 str = s->convertEncoding(qe, xsink);
1164 temp = true;
1165 } else {
1166 str = const_cast<QoreString* >(s);
1167 temp = false;
1168 }
1169 }
1170 };
1171
1173
1175 DLLEXPORT size_t qore_get_unicode_character_width(int ucs);
1176
1177 #endif
QoreString::c_str
DLLEXPORT const char * c_str() const
returns the string&#39;s buffer; this data should not be changed
QoreString::trim_trailing
DLLEXPORT void trim_trailing(const char *chars=0)
remove trailing whitespace or other characters
QoreString::QoreString
DLLEXPORT QoreString()
creates an empty string and assigns the default encoding QCS_DEFAULT
QoreString::takeAndTerminate
DLLEXPORT void takeAndTerminate(char *str, size_t size)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
QoreString::parseBase64
DLLEXPORT BinaryNode * parseBase64(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a BinaryNode pointer (caller ...
QoreString::setEncoding
DLLEXPORT void setEncoding(const QoreEncoding *new_encoding)
changes the tagged encoding to the given encoding; does not affect the actual string buffer...
QoreString::priv
struct qore_string_private * priv
the private implementation of QoreString
Definition: QoreString.h:953
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
QoreString::parseHex
DLLEXPORT BinaryNode * parseHex(ExceptionSink *xsink) const
parses the current string data as hexadecimal-encoded data and returns it as a BinaryNode pointer (ca...
QoreString::parseBase64ToString
DLLEXPORT QoreString * parseBase64ToString(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a QoreString pointer owned by...
QoreString::getUnicodePointFromBytePos
DLLEXPORT unsigned int getUnicodePointFromBytePos(size_t offset, unsigned &len, ExceptionSink *xsink) const
return Unicode code point for the given byte offset
QoreString::empty
DLLEXPORT bool empty() const
returns true if the string is empty, false if not
QoreString::concatDecodeUrl
DLLEXPORT void concatDecodeUrl(const char *url)
concatenates a URL-decoded version of the c-string passed
QoreString::replaceAll
DLLEXPORT void replaceAll(const char *old_str, const char *new_str)
replaces all occurences of the first string with the second string
QoreString::rindex
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...
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
QoreString::strlen
DLLEXPORT size_t strlen() const
returns number of bytes in the string (not including the null pointer)
QoreString::concatEscape
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) ...
QoreString::equalSoft
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...
QoreString::trim_single_trailing
DLLEXPORT void trim_single_trailing(char c)
remove a single trailing character if present
QoreString::rfindAny
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 ...
QoreString::find
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 ...
QoreString::convertEncoding
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...
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
QoreString::brindex
DLLEXPORT qore_offset_t brindex(const QoreString &needle, qore_offset_t pos=-1) const
returns the byte position of a substring within the string searching in reverse from a given position...
QoreString::giveBuffer
DLLEXPORT char * giveBuffer()
returns the character buffer and leaves the QoreString empty, the caller owns the memory returned (mu...
QoreString::sprintf
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
QoreString::index
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 ...
QoreString::concatISO8601DateTime
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...
QoreString::insert
DLLEXPORT int insert(const char *str, size_t pos)
inserts a character string at a certain position in the string
QoreString::tolwr
DLLEXPORT void tolwr()
converts the string to lower-case in place
QoreString::prepend
DLLEXPORT void prepend(const char *str)
prepends the string given to the string, assumes character encoding is the same as the string&#39;s ...
QoreString::splice
DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset"
QoreString::operator[]
DLLEXPORT int operator[](qore_offset_t pos) const
returns the byte (not character) at the given location; if the location is invalid, returns -1
QoreString::concatUTF8FromUnicode
DLLEXPORT void concatUTF8FromUnicode(unsigned code)
append a UTF-8 character sequence from a unicode code point, assumes the string is tagged with QCS_UT...
QoreString::concatDecodeUriRequest
DLLEXPORT int concatDecodeUriRequest(const QoreString &url, ExceptionSink *xsink)
concatenates a URI-decoded version of the c-string passed
QoreString::concatHex
DLLEXPORT void concatHex(const char *buf, size_t size)
concatenates hexidecimal digits corresponding to the binary data passed up to byte "len" ...
QoreString::isDataAscii
DLLEXPORT bool isDataAscii() const
returns true if the string is empty or has no characters with the high bit set (ie all characters < 1...
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreString::copy
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
QoreString::substr
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...
CE_XHTML
#define CE_XHTML
code for encoding XHTML entities
Definition: QoreString.h:55
QoreString::getBuffer
DLLEXPORT const char * getBuffer() const
returns the string&#39;s buffer; this data should not be changed
TempString
class used to hold a possibly temporary QoreString pointer, stack only, cannot be dynamically allocat...
Definition: QoreString.h:992
QoreString::concat
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
QoreString::size
DLLEXPORT size_t size() const
returns number of bytes in the string (not including the null pointer)
TempEncodingHelper::is_temp
DLLLOCAL bool is_temp() const
returns true if a temporary string is being managed
Definition: QoreString.h:1100
QoreString::toupr
DLLEXPORT void toupr()
converts the string to upper-case in place
QoreString::getUnicodePointFromUTF8
DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset=0) const
return Unicode code point for character offset, string must be UTF-8
QoreString::operator==
DLLEXPORT bool operator==(const QoreString &other) const
returns true if the other string is equal to this string (encodings also must be equal) ...
TempString::release
DLLLOCAL QoreString * release()
releases the QoreString pointer being managed and sets the internal pointer to 0
Definition: QoreString.h:1022
QoreString::reserve
DLLEXPORT void reserve(size_t size)
ensures that at least the given size is available in the string; the string&#39;s contents are not affect...
QoreString::startsWith
DLLEXPORT bool startsWith(const char *str) const
returns true if the current string starts with the argument string (bytes)
QoreString::equalPartialPath
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...
QoreString::equalPartialSoft
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...
CD_ALL
#define CD_ALL
code for decoding everything
Definition: QoreString.h:73
QoreString::bindex
DLLEXPORT qore_offset_t bindex(const QoreString &needle, qore_offset_t pos=0) const
returns the byte position of a substring within the string or -1 if not found
QoreString::length
DLLEXPORT size_t length() const
returns the number of characters (not bytes) in the string
TempEncodingHelper
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1051
QoreString::findAny
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...
QoreString::operator!=
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:821
QoreString::getUnicodePoint
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...
QoreString::replaceChar
DLLEXPORT void replaceChar(size_t offset, char c)
replaces a byte with the byte passed
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
QoreString::concatDecode
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...
QoreString::concatAndHTMLEncode
DLLEXPORT void concatAndHTMLEncode(const char *str)
concatenates HTML-encoded version of the c-string passed
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
TempEncodingHelper::operator*
DLLLOCAL const QoreString * operator*()
returns the string being managed
Definition: QoreString.h:1116
TempString::~TempString
DLLLOCAL ~TempString()
deletes the QoreString pointer being managed
Definition: QoreString.h:1008
QoreString::equalPartial
DLLEXPORT bool equalPartial(const QoreString &str) const
returns true if the beginning of the current string matches the argument string, false if not...
QoreString::concatEncode
DLLEXPORT int concatEncode(ExceptionSink *xsink, const QoreString &str, unsigned code=CE_XHTML)
concatenates a string and encodes it according to the encoding argument passed
QoreString::concatEncodeUrl
DLLEXPORT int concatEncodeUrl(ExceptionSink *xsink, const QoreString &url, bool encode_all=false)
concatenates a URL-encoded version of the c-string passed
QoreString::replace
DLLEXPORT void replace(size_t offset, size_t len, const char *str)
replaces bytes with the string passed
QoreString::concatBase64
DLLEXPORT void concatBase64(const char *buf, size_t size)
concatenates the base64-encoded version of the binary data passed
QoreString::trim_leading
DLLEXPORT void trim_leading(const char *chars=0)
remove leading whitespace or other characters
int64
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
QoreString::addch
DLLEXPORT void addch(char c, unsigned times)
append a character to the string a number of times
TempEncodingHelper::makeTemp
DLLLOCAL void makeTemp()
ensures that the object is holding a temporary value
Definition: QoreString.h:1105
TempEncodingHelper::TempEncodingHelper
DLLLOCAL TempEncodingHelper()
creates an empty TempEncodingHelperObject that may be initialized with TempEncodingHelper::set() late...
Definition: QoreString.h:1074
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
TempEncodingHelper::~TempEncodingHelper
DLLLOCAL ~TempEncodingHelper()
deletes any temporary string being managed by the object
Definition: QoreString.h:1078
QoreString::terminate
DLLEXPORT void terminate(size_t size)
terminates the string at byte position "size", the string is reallocated if necessary ...
QoreString::trim
DLLEXPORT void trim(const char *chars=0)
remove leading and trailing whitespace or other characters
TempString::operator->
DLLLOCAL QoreString * operator->()
returns the QoreString pointer being managed
Definition: QoreString.h:1013
QoreString::getByteOffset
DLLEXPORT qore_offset_t getByteOffset(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 ...
QoreString::rfind
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 ...
QoreString::getCharWidth
DLLEXPORT size_t getCharWidth(ExceptionSink *xsink) const
returns the character width of the string
QoreString::trimTrailing
DLLEXPORT int trimTrailing(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes trailing whitespace or other characters
QoreString::concatUnicode
DLLEXPORT int concatUnicode(unsigned code, ExceptionSink *xsink)
append a character sequence from a unicode code point (returns 0 for OK, -1 for exception) ...
QoreString::operator+=
DLLEXPORT QoreString & operator+=(const char *str)
concatenates the characters to the string; assumes the string to be concatenated is already in the ch...
QoreString::equal
DLLEXPORT bool equal(const QoreString &str) const
returns true if the strings are equal, false if not, if the character encodings are different...
QoreString::insertch
DLLEXPORT int insertch(char c, size_t pos, unsigned times)
insert a character at a certain position in the string a number of times
QoreString::~QoreString
DLLEXPORT ~QoreString()
frees any memory allocated by the string
QoreString::endsWith
DLLEXPORT bool endsWith(const char *str) const
returns true if the current string ends with the argument string (bytes)
QoreString::extract
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...
QoreString::toBigInt
DLLEXPORT int64 toBigInt() const
returns the value of the string as an int64
QoreString::allocate
DLLEXPORT void allocate(unsigned requested_size)
Ensure the internal buffer has at least expected size in bytes.
QoreString::trimLeading
DLLEXPORT int trimLeading(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes leading whitespace or other characters
QoreString::getEncoding
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding for the string
QoreString::isDataPrintableAscii
DLLEXPORT bool isDataPrintableAscii() const
returns true if the string is empty or only contains printable non-control ASCII characters (ie all c...
QoreString::compareSoft
DLLEXPORT int compareSoft(const QoreString *str, ExceptionSink *xsink) const
compares the string with another string, performing character set encoding conversion if necessary ...
TempEncodingHelper::giveBuffer
DLLLOCAL char * giveBuffer()
returns a char pointer of the string, the caller owns the pointer returned (it must be manually freed...
Definition: QoreString.h:1128
QoreString::reset
DLLEXPORT void reset()
reset string to zero length; memory is deallocated; string encoding is reset to QCS_DEFAULT ...
QoreString::clear
DLLEXPORT void clear()
reset string to zero length; memory is not deallocated; string encoding does not change ...
QoreString::capacity
DLLEXPORT size_t capacity() const
returns number of bytes allocated for the string&#39;s buffer, capacity is always >= size ...
TempEncodingHelper::removeBom
DLLEXPORT void removeBom()
remove any leading byte order marker (BOM) from UTF-16* strings
TempString::operator*
DLLLOCAL QoreString * operator*()
returns the QoreString pointer being managed
Definition: QoreString.h:1016
QoreString::concatAndHTMLDecode
DLLEXPORT void concatAndHTMLDecode(const QoreString *str)
concatenates HTML-decoded version of the c-string passed
QoreString::trim_single_leading
DLLEXPORT void trim_single_leading(char c)
remove a single leading character if present
QoreString::vsprintf
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...
QoreString::compare
DLLEXPORT int compare(const QoreString *str) const
compares two strings without converting encodings (if the encodings do not match then "this" is deeme...
TempEncodingHelper::operator->
DLLLOCAL const QoreString * operator->()
returns the string being managed
Definition: QoreString.h:1113
QoreString::take
DLLEXPORT void take(char *str)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
TempString::TempString
DLLLOCAL TempString()
populates the object with a new QoreString that this object will manage
Definition: QoreString.h:995
QoreString::operator=
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
QoreString::concatEncodeUriRequest
DLLEXPORT int concatEncodeUriRequest(ExceptionSink *xsink, const QoreString &url)
concatenates a URI-encoded version of the c-string passed
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
QoreString::chomp
DLLEXPORT size_t chomp()
removes a single \n\r or \n from the end of the string and returns the number of characters removed ...
QoreString::reverse
DLLEXPORT QoreString * reverse() const
return a Qorestring with the characters reversed