Qore Programming Language  0.9.16
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 - 2020 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 
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, qore_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, qore_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, qore_size_t maxlinelen);
132 
134  DLLEXPORT QoreString(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
135 
137  DLLEXPORT ~QoreString();
138 
140 
142  DLLEXPORT qore_size_t length() const;
143 
145  DLLEXPORT void set(const char* str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
146 
148  DLLEXPORT void set(const std::string& str, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
149 
151  DLLEXPORT void set(const QoreString* str);
152 
154  DLLEXPORT void set(const QoreString& str);
155 
157  DLLEXPORT void set(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
158 
160  DLLEXPORT void setEncoding(const QoreEncoding* new_encoding);
161 
163 
173  DLLEXPORT int concatEncode(ExceptionSink* xsink, const QoreString& str, unsigned code = CE_XHTML);
174 
176 
188  DLLEXPORT int concatDecode(ExceptionSink* xsink, const QoreString& str, unsigned code = CD_ALL);
189 
191 
194  DLLEXPORT void concatAndHTMLEncode(const char* str);
195 
197 
200  DLLEXPORT void concatAndHTMLDecode(const QoreString* str);
201 
203 
206  DLLEXPORT void concatAndHTMLDecode(const char* str, size_t slen);
207 
209 
212  DLLEXPORT void concatAndHTMLDecode(const char* str);
213 
215 
217  DLLEXPORT void concatDecodeUrl(const char* url);
218 
220  DLLEXPORT int concatDecodeUrl(const QoreString& url, ExceptionSink* xsink);
221 
223 
227  DLLEXPORT int concatEncodeUrl(ExceptionSink* xsink, const QoreString& url, bool encode_all = false);
228 
230 
233  DLLEXPORT int concatDecodeUriRequest(const QoreString& url, ExceptionSink* xsink);
234 
236 
241  DLLEXPORT int concatEncodeUriRequest(ExceptionSink* xsink, const QoreString& url);
242 
244  DLLEXPORT void concatEscape(const QoreString* str, char c, char esc_char, ExceptionSink* xsink);
245 
247  DLLEXPORT void concatEscape(const char* str, char c, char esc_char = '\\');
248 
250 
256  DLLEXPORT void concatAndHTMLEncode(const QoreString* str, ExceptionSink* xsink);
257 
259  DLLEXPORT void concat(const QoreString* str, ExceptionSink* xsink);
260 
262 
268  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, ExceptionSink* xsink);
269 
271 
278  DLLEXPORT int concat(const QoreString& str, qore_offset_t pos, qore_offset_t len, ExceptionSink* xsink);
279 
281 
286  DLLEXPORT void concat(const QoreString* str, qore_size_t size, ExceptionSink* xsink);
287 
289  DLLEXPORT void concatBase64(const char* buf, qore_size_t size);
290 
292  DLLEXPORT void concatBase64(const BinaryNode* bin);
293 
295  DLLEXPORT void concatBase64(const QoreString* str);
296 
298  DLLEXPORT void concatBase64(const char* buf, qore_size_t size, qore_size_t maxlinelen);
299 
301  DLLEXPORT void concatBase64(const BinaryNode* bin, qore_size_t maxlinelen);
302 
304  DLLEXPORT void concatBase64(const QoreString* str, qore_size_t maxlinelen);
305 
307 
311  DLLEXPORT BinaryNode* parseBase64(ExceptionSink* xsink) const;
312 
314 
318  DLLEXPORT QoreString* parseBase64ToString(ExceptionSink* xsink) const;
319 
321 
326  DLLEXPORT QoreString* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
327 
329 
331  DLLEXPORT void concatHex(const char* buf, qore_size_t size);
332 
334  DLLEXPORT void concatHex(const BinaryNode* bin);
335 
337  DLLEXPORT void concatHex(const QoreString* str);
338 
340 
344  DLLEXPORT BinaryNode* parseHex(ExceptionSink* xsink) const;
345 
347  DLLEXPORT void concat(const DateTime* d);
348 
350  DLLEXPORT void concatISO8601DateTime(const DateTime* d);
351 
353  DLLEXPORT void concat(const char* str);
354 
356  DLLEXPORT void concat(const std::string& str);
357 
359  DLLEXPORT void concat(const char* str, qore_size_t size);
360 
362  DLLEXPORT void concat(const char c);
363 
365 
370  DLLEXPORT int compareSoft(const QoreString* str, ExceptionSink* xsink) const;
371 
373 
377  DLLEXPORT int compare(const QoreString* str) const;
378 
380 
384  DLLEXPORT int compare(const char* str) const;
385 
387 
389  DLLEXPORT bool equal(const QoreString& str) const;
390 
392 
394  DLLEXPORT bool equal(const char* str) const;
395 
397 
403  DLLEXPORT bool equalSoft(const QoreString& str, ExceptionSink* xsink) const;
404 
406 
408  DLLEXPORT bool equalPartial(const QoreString& str) const;
409 
411 
413  DLLEXPORT bool equalPartial(const char* str) const;
414 
416 
422  DLLEXPORT bool equalPartialSoft(const QoreString& str, ExceptionSink* xsink) const;
423 
425 
431  DLLEXPORT bool equalPartialPath(const QoreString& str, ExceptionSink* xsink) const;
432 
434  DLLEXPORT void terminate(qore_size_t size);
435 
437 
439  DLLEXPORT void reserve(qore_size_t size);
440 
442 
444  DLLEXPORT int sprintf(const char* fmt, ...);
445 
447 
449  DLLEXPORT int vsprintf(const char* fmt, va_list args);
450 
452 
454  DLLEXPORT void take(char* str);
455 
457  DLLEXPORT void take(char* str, const QoreEncoding* enc);
459 
460  DLLEXPORT void take(char* str, qore_size_t size);
461 
463  DLLEXPORT void take(char* str, qore_size_t size, const QoreEncoding* enc);
464 
466  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size);
467 
469  DLLEXPORT void takeAndTerminate(char* str, qore_size_t size, const QoreEncoding* enc);
470 
472 
477  DLLEXPORT QoreString* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
478 
480 
483  DLLEXPORT char* giveBuffer();
484 
486  DLLEXPORT void clear();
487 
489 
491  DLLEXPORT void reset();
492 
494 
496  DLLEXPORT void replaceAll(const char* old_str, const char* new_str);
497 
499 
501  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char* str);
502 
504 
509  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str);
510 
512 
514  DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString* str, ExceptionSink* xsink);
515 
517 
519  DLLEXPORT void replaceChar(qore_size_t offset, char c);
520 
522 
526  DLLEXPORT void splice(qore_offset_t offset, ExceptionSink* xsink);
527 
529 
534  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
535 
537 
543  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink* xsink);
544 
546 
552  DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString& str, ExceptionSink* xsink);
553 
555 
560  DLLEXPORT QoreString* extract(qore_offset_t offset, ExceptionSink* xsink);
561 
563 
570 
572 
579  DLLEXPORT QoreString* extract(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink* xsink);
580 
582 
587  DLLEXPORT QoreString* substr(qore_offset_t offset, ExceptionSink* xsink) const;
588 
590 
596  DLLEXPORT QoreString* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
597 
599  DLLEXPORT qore_size_t chomp();
600 
602  DLLEXPORT const QoreEncoding* getEncoding() const;
603 
605  DLLEXPORT QoreString* copy() const;
606 
608 
610  DLLEXPORT void tolwr();
611 
613 
615  DLLEXPORT void toupr();
616 
618  DLLEXPORT qore_size_t strlen() const;
619 
621  DLLEXPORT qore_size_t size() const;
622 
624  DLLEXPORT qore_size_t capacity() const;
625 
627  DLLEXPORT const char* getBuffer() const;
628 
630  DLLEXPORT const char* c_str() const;
631 
633 
635  DLLEXPORT void allocate(unsigned requested_size);
636 
638 
644  DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times);
645 
647 
652  DLLEXPORT int insert(const char* str, qore_size_t pos);
653 
655  DLLEXPORT void addch(char c, unsigned times);
656 
658 
664  DLLEXPORT void concatUTF8FromUnicode(unsigned code);
665 
667 
671  DLLEXPORT int concatUnicode(unsigned code, ExceptionSink* xsink);
672 
674 
678  DLLEXPORT int concatUnicode(unsigned code);
679 
681 
684  DLLEXPORT QoreString* reverse() const;
685 
687 
689  DLLEXPORT void trim_trailing(const char* chars = 0);
690 
692 
694  DLLEXPORT void trim_leading(const char* chars = 0);
695 
697 
699  DLLEXPORT void trim(const char* chars = 0);
700 
702 
704  DLLEXPORT void trim_trailing(char c);
705 
707 
709  DLLEXPORT void trim_single_trailing(char c);
710 
712 
714  DLLEXPORT void trim_leading(char c);
715 
717 
719  DLLEXPORT void trim_single_leading(char c);
720 
722 
724  DLLEXPORT void trim(char c);
725 
727 
733  DLLEXPORT int trim(ExceptionSink* xsink, const QoreString* chars = nullptr);
734 
736 
742  DLLEXPORT int trimLeading(ExceptionSink* xsink, const QoreString* chars = nullptr);
743 
745 
751  DLLEXPORT int trimTrailing(ExceptionSink* xsink, const QoreString* chars = nullptr);
752 
754 
758  DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
759 
761 
766  DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink* xsink) const;
767 
769 
777  DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned& len, ExceptionSink* xsink) const;
778 
780  DLLEXPORT void prepend(const char* str);
781 
783  DLLEXPORT void prepend(const char* str, qore_size_t size);
784 
786  DLLEXPORT QoreString& operator=(const QoreString& other);
787 
789  DLLEXPORT QoreString& operator=(const char* other);
790 
792  DLLEXPORT QoreString& operator=(const std::string& other);
793 
795  DLLEXPORT bool operator==(const QoreString& other) const;
796 
798  DLLEXPORT bool operator==(const std::string& other) const;
799 
801  DLLEXPORT bool operator==(const char* other) const;
802 
804  DLLLOCAL bool operator!=(const QoreString& other) const {
805  return !(*this == other);
806  }
807 
809  DLLLOCAL bool operator!=(const std::string& other) const {
810  return !(*this == other);
811  }
812 
814  DLLLOCAL bool operator!=(const char* other) const {
815  return !(*this == other);
816  }
817 
819 
824  DLLEXPORT char operator[](qore_offset_t pos) const;
825 
827  DLLEXPORT QoreString& operator+=(const char* str);
828 
830  DLLEXPORT QoreString& operator+=(const std::string& str);
831 
833  DLLEXPORT bool empty() const;
834 
836  DLLEXPORT qore_offset_t index(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
837 
839  DLLEXPORT qore_offset_t bindex(const QoreString& needle, qore_offset_t pos) const;
840 
842  DLLEXPORT qore_offset_t bindex(const char* needle, qore_offset_t pos) const;
843 
845  DLLEXPORT qore_offset_t bindex(const std::string& needle, qore_offset_t pos) const;
846 
848 
854  DLLEXPORT qore_offset_t rindex(const QoreString& needle, qore_offset_t pos, ExceptionSink* xsink) const;
855 
857  DLLEXPORT qore_offset_t brindex(const QoreString& needle, qore_offset_t pos) const;
858 
860  DLLEXPORT qore_offset_t brindex(const char* needle, qore_offset_t pos) const;
861 
863  DLLEXPORT qore_offset_t brindex(const std::string& needle, qore_offset_t pos) const;
864 
866  DLLEXPORT qore_offset_t find(char c, qore_offset_t pos = 0) const;
867 
869  DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos = -1) const;
870 
872  DLLEXPORT qore_offset_t findAny(const char *str, qore_offset_t pos = 0) const;
873 
875  DLLEXPORT qore_offset_t rfindAny(const char *str, qore_offset_t pos = -1) const;
876 
878 
880  DLLEXPORT bool isDataPrintableAscii() const;
881 
883 
885  DLLEXPORT bool isDataAscii() const;
886 
888  DLLEXPORT int64 toBigInt() const;
889 
891 
899  DLLEXPORT size_t getCharWidth(ExceptionSink* xsink) const;
900 
902 
907  DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink* xsink) const;
908 
909  // concatenates a qorestring without converting encodings - internal only
910  DLLLOCAL void concat(const QoreString* str);
911 
912  // private constructor
913  DLLLOCAL QoreString(struct qore_string_private* p);
914 
915 protected:
917  hashdecl qore_string_private* priv = nullptr;
918 
919  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, QoreString* extract = 0);
920  DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char* str, qore_size_t str_len, QoreString* extract = 0);
921  DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink* xsink, QoreString* extract = 0);
922  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink, QoreString* extract = 0);
923  DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString* str, ExceptionSink* xsink, QoreString* extract = 0);
924  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset) const;
925  DLLLOCAL int substr_simple(QoreString* str, qore_offset_t offset, qore_offset_t length) const;
926  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, ExceptionSink* xsink) const;
927  DLLLOCAL int substr_complex(QoreString* str, qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
928 
929  // writes a new QoreString with the characters reversed of the "this" QoreString
930  // assumes the encoding is the same and the length is 0
931  DLLLOCAL void concat_reverse(QoreString* targ) const;
932 
933  DLLLOCAL int snprintf(size_t size, const char* fmt, ...);
934  DLLLOCAL int vsnprintf(size_t size, const char* fmt, va_list args);
935 };
936 
937 DLLEXPORT QoreString* checkEncoding(const QoreString* str, const QoreEncoding* enc, ExceptionSink* xsink);
938 
939 class QoreStringMaker : public QoreString {
940 public:
942 
944  DLLEXPORT QoreStringMaker(const char* fmt, ...);
945 
947 
949  DLLEXPORT QoreStringMaker(const QoreEncoding* enc, const char* fmt, ...);
950 
951 private:
952  DLLLOCAL QoreStringMaker(const QoreStringMaker& str) = delete;
953  DLLLOCAL QoreStringMaker& operator=(const QoreStringMaker&) = delete;
954 };
955 
957 
966 class TempString {
967 public:
969  DLLLOCAL TempString() : str(new QoreString) {
970  }
971 
973  DLLLOCAL TempString(const QoreEncoding* enc) : str(new QoreString(enc)) {
974  }
975 
977  DLLLOCAL TempString(QoreString* s) {
978  str = s;
979  }
980 
982  DLLLOCAL ~TempString() {
983  delete str;
984  }
985 
987  DLLLOCAL QoreString* operator->(){ return str; };
988 
990  DLLLOCAL QoreString* operator*() { return str; };
991 
993  DLLLOCAL operator bool() const { return str != nullptr; }
994 
996  DLLLOCAL QoreString* release() {
997  QoreString* rv = str;
998  str = nullptr;
999  return rv;
1000  }
1001 
1002 private:
1003  QoreString* str;
1004 
1005  TempString(const TempString&) = delete;
1006  TempString& operator=(const TempString&) = delete;
1007  void* operator new(size_t) = delete;
1008 };
1009 
1011 
1026 public:
1028 
1033  DLLLOCAL TempEncodingHelper(const QoreString& s, const QoreEncoding* qe, ExceptionSink* xsink) {
1034  set_intern(&s, qe, xsink);
1035  }
1036 
1038 
1043  DLLLOCAL TempEncodingHelper(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1044  set_intern(s, qe, xsink);
1045  }
1046 
1048  DLLLOCAL TempEncodingHelper() {
1049  }
1050 
1052  DLLLOCAL ~TempEncodingHelper() {
1053  discard_intern();
1054  }
1055 
1057 
1066  DLLLOCAL int set(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1067  discard_intern();
1068 
1069  set_intern(s, qe, xsink);
1070  return str != nullptr;
1071  }
1072 
1074  DLLLOCAL bool is_temp() const {
1075  return temp;
1076  }
1077 
1079  DLLLOCAL void makeTemp() {
1080  if (!temp && str) {
1081  str = new QoreString(*str);
1082  temp = true;
1083  }
1084  }
1085 
1087  DLLLOCAL const QoreString* operator->(){ return str; };
1088 
1090  DLLLOCAL const QoreString* operator*() { return str; };
1091 
1093 
1096  DLLLOCAL operator bool() const { return str != 0; }
1097 
1099 
1102  DLLLOCAL char* giveBuffer() {
1103  if (!str)
1104  return nullptr;
1105  if (temp)
1106  return str->giveBuffer();
1107  return strdup(str->getBuffer());
1108  }
1109 
1111 
1113  DLLEXPORT void removeBom();
1114 
1115 private:
1116  QoreString* str = nullptr;
1117  bool temp = false;
1118 
1119  DLLLOCAL TempEncodingHelper(const TempEncodingHelper&) = delete;
1120  DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper&) = delete;
1121  DLLLOCAL void* operator new(size_t) = delete;
1122 
1124  DLLLOCAL void discard_intern() {
1125  if (temp && str)
1126  delete str;
1127  }
1128 
1130 
1135  DLLLOCAL void set_intern(const QoreString* s, const QoreEncoding* qe, ExceptionSink* xsink) {
1136  if (s->getEncoding() != qe) {
1137  str = s->convertEncoding(qe, xsink);
1138  temp = true;
1139  } else {
1140  str = const_cast<QoreString* >(s);
1141  temp = false;
1142  }
1143  }
1144 };
1145 
1147 
1149 DLLEXPORT size_t qore_get_unicode_character_width(int ucs);
1150 
1151 #endif
QoreString::getUnicodePointFromBytePos
DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned &len, ExceptionSink *xsink) const
return Unicode code point for the given byte offset
QoreString::toBigInt
DLLEXPORT int64 toBigInt() const
returns the value of the string as an int64
QoreString::giveBuffer
DLLEXPORT char * giveBuffer()
returns the character buffer and leaves the QoreString empty, the caller owns the memory returned (mu...
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::~QoreString
DLLEXPORT ~QoreString()
frees any memory allocated by the string
QoreString::concatHex
DLLEXPORT void concatHex(const char *buf, qore_size_t size)
concatenates hexidecimal digits corresponding to the binary data passed up to byte "len"
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::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::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::brindex
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...
QoreString::getByteOffset
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 ...
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
TempString::operator*
DLLLOCAL QoreString * operator*()
returns the QoreString pointer being managed
Definition: QoreString.h:990
QoreString::size
DLLEXPORT qore_size_t size() const
returns number of bytes in the string (not including the null pointer)
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
QCS_DEFAULT
const DLLEXPORT QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
QoreString::getEncoding
const DLLEXPORT QoreEncoding * getEncoding() const
returns the encoding for the string
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
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
TempEncodingHelper::~TempEncodingHelper
DLLLOCAL ~TempEncodingHelper()
deletes any temporary string being managed by the object
Definition: QoreString.h:1052
QoreString::reverse
DLLEXPORT QoreString * reverse() const
return a Qorestring with the characters reversed
QoreString::QoreString
DLLEXPORT QoreString()
creates an empty string and assigns the default encoding QCS_DEFAULT
QoreString::trim_trailing
DLLEXPORT void trim_trailing(const char *chars=0)
remove trailing whitespace or other characters
QoreString::operator[]
DLLEXPORT char operator[](qore_offset_t pos) const
returns the byte (not character) at the given location; if the location is invalid,...
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
QoreString::toupr
DLLEXPORT void toupr()
converts the string to upper-case in place
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:996
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::concatBase64
DLLEXPORT void concatBase64(const char *buf, qore_size_t size)
concatenates the base64-encoded version of the binary data passed
QoreString::trim_single_trailing
DLLEXPORT void trim_single_trailing(char c)
remove a single trailing character if present
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:1102
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 ...
TempEncodingHelper::set
DLLLOCAL int set(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink)
discards any current state and sets and converts (if necessary) a new string to the desired encoding
Definition: QoreString.h:1066
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::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,...
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,...
TempEncodingHelper::makeTemp
DLLLOCAL void makeTemp()
ensures that the object is holding a temporary value
Definition: QoreString.h:1079
TempEncodingHelper::operator->
const DLLLOCAL QoreString * operator->()
returns the string being managed
Definition: QoreString.h:1087
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::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::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::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::concatAndHTMLEncode
DLLEXPORT void concatAndHTMLEncode(const char *str)
concatenates HTML-encoded version of the c-string passed
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:804
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreString::c_str
const DLLEXPORT char * c_str() const
returns the string'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:966
QoreString::insert
DLLEXPORT int insert(const char *str, qore_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's
QoreString::splice
DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset"
QoreString::terminate
DLLEXPORT void terminate(qore_size_t size)
terminates the string at byte position "size", the string is reallocated if necessary
TempEncodingHelper::is_temp
DLLLOCAL bool is_temp() const
returns true if a temporary string is being managed
Definition: QoreString.h:1074
QoreString::concatEncodeUrl
DLLEXPORT int concatEncodeUrl(ExceptionSink *xsink, const QoreString &url, bool encode_all=false)
concatenates a URL-encoded version of the c-string passed
TempString::operator->
DLLLOCAL QoreString * operator->()
returns the QoreString pointer being managed
Definition: QoreString.h:987
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::trimTrailing
DLLEXPORT int trimTrailing(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes trailing whitespace or other characters
QoreString::addch
DLLEXPORT void addch(char c, unsigned times)
append a character to the string a number of times
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::replace
DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char *str)
replaces bytes with the string passed
QoreString::getBuffer
const DLLEXPORT char * getBuffer() const
returns the string's buffer; this data should not be changed
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::concat
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
TempEncodingHelper
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1025
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...
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::insertch
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
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::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
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::strlen
DLLEXPORT qore_size_t strlen() const
returns number of bytes in the string (not including the null pointer)
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::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::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...
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
TempEncodingHelper::removeBom
DLLEXPORT void removeBom()
remove any leading byte order marker (BOM) from UTF-16* strings
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::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:969
QoreString::length
DLLEXPORT qore_size_t length() const
returns the number of characters (not bytes) in the string
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...
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
TempEncodingHelper::operator*
const DLLLOCAL QoreString * operator*()
returns the string being managed
Definition: QoreString.h:1090
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::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::replaceChar
DLLEXPORT void replaceChar(qore_size_t offset, char c)
replaces a byte with the byte passed
TempString::~TempString
DLLLOCAL ~TempString()
deletes the QoreString pointer being managed
Definition: QoreString.h:982
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::capacity
DLLEXPORT qore_size_t capacity() const
returns number of bytes allocated for the string's buffer, capacity is always >= size
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::empty
DLLEXPORT bool empty() const
returns true if the string is empty, false if not
QoreString::bindex
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
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 ...
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
TempEncodingHelper::TempEncodingHelper
DLLLOCAL TempEncodingHelper()
creates an empty TempEncodingHelperObject that may be initialized with TempEncodingHelper::set() late...
Definition: QoreString.h:1048
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
hashdecl qore_string_private * priv
the private implementation of QoreString
Definition: QoreString.h:917
QoreString::concatDecodeUrl
DLLEXPORT void concatDecodeUrl(const char *url)
concatenates a URL-decoded version of the c-string passed
QoreString::trim_leading
DLLEXPORT void trim_leading(const char *chars=0)
remove leading whitespace or other characters
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::getCharWidth
DLLEXPORT size_t getCharWidth(ExceptionSink *xsink) const
returns the character width of the string
QoreString::set
DLLEXPORT void set(const char *str, const QoreEncoding *new_qorecharset=QCS_DEFAULT)
copies the c-string passed and sets the value of the string and its encoding
QoreString::trim
DLLEXPORT void trim(const char *chars=0)
remove leading and trailing whitespace or other characters
QoreString::chomp
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
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::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...
QoreString::reserve
DLLEXPORT void reserve(qore_size_t size)
ensures that at least the given size is available in the string; the string's contents are not affect...
QoreString::takeAndTerminate
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...