00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _QORE_QORESTRING_H
00026
00027 #define _QORE_QORESTRING_H
00028
00029 #include <stdarg.h>
00030
00031 #include <string>
00032
00033 class DateTime;
00034 class BinaryNode;
00035
00037
00041 class QoreString {
00042 protected:
00044 struct qore_string_private *priv;
00045
00047 DLLLOCAL QoreString & operator=(const QoreString &);
00048
00049 DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length);
00050 DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char *str, qore_size_t str_len);
00051 DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink *xsink);
00052 DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
00053 DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString *str, ExceptionSink *xsink);
00054 DLLLOCAL int substr_simple(QoreString *str, qore_offset_t offset) const;
00055 DLLLOCAL int substr_simple(QoreString *str, qore_offset_t offset, qore_offset_t length) const;
00056 DLLLOCAL int substr_complex(QoreString *str, qore_offset_t offset, ExceptionSink *xsink) const;
00057 DLLLOCAL int substr_complex(QoreString *str, qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const;
00058
00059
00060
00061 DLLLOCAL void concat_reverse(QoreString *targ) const;
00062
00063 DLLLOCAL int snprintf(size_t size, const char *fmt, ...);
00064 DLLLOCAL int vsnprintf(size_t size, const char *fmt, va_list args);
00065 DLLLOCAL static int convert_encoding_intern(const char *src, qore_size_t src_len, const QoreEncoding *from, QoreString &targ, const QoreEncoding *to, ExceptionSink *xsink);
00066
00067 public:
00069 DLLEXPORT QoreString();
00070
00072 DLLEXPORT QoreString(bool b);
00073
00075 DLLEXPORT QoreString(const char *str);
00076
00078 DLLEXPORT QoreString(const char *str, const QoreEncoding *new_qorecharset);
00079
00081 DLLEXPORT QoreString(const QoreEncoding *new_qorecharset);
00082
00084 DLLEXPORT QoreString(const char *str, qore_size_t len, const QoreEncoding *new_qorecharset = QCS_DEFAULT);
00085
00087 DLLEXPORT QoreString(const std::string &str, const QoreEncoding *new_encoding = QCS_DEFAULT);
00088
00090 DLLEXPORT QoreString(char c);
00091
00093 DLLEXPORT QoreString(const QoreString &str);
00094
00096 DLLEXPORT QoreString(const QoreString *str);
00097
00099 DLLEXPORT QoreString(const QoreString *str, qore_size_t len);
00100
00102 DLLEXPORT QoreString(int64 i);
00103
00105 DLLEXPORT QoreString(double f);
00106
00108 DLLEXPORT QoreString(const DateTime *date);
00109
00111 DLLEXPORT QoreString(const BinaryNode *bin);
00112
00114 DLLEXPORT QoreString(char *nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding *enc);
00115
00117 DLLEXPORT ~QoreString();
00118
00120
00122 DLLEXPORT qore_size_t length() const;
00123
00125 DLLEXPORT void set(const char *str, const QoreEncoding *new_qorecharset = QCS_DEFAULT);
00126
00128 DLLEXPORT void set(const QoreString *str);
00129
00131 DLLEXPORT void set(const QoreString &str);
00132
00134 DLLEXPORT void concatAndHTMLEncode(const char *str);
00135
00137 DLLEXPORT void concatAndHTMLDecode(const QoreString *str);
00138
00140 DLLEXPORT void concatEscape(const QoreString *, char c, char esc_char, ExceptionSink *xsink);
00141
00143 DLLEXPORT void concatEscape(const char *, char c, char esc_char = '\\');
00144
00146 DLLEXPORT void concatAndHTMLEncode(const QoreString *, ExceptionSink *xsink);
00147
00149 DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink);
00150
00152
00157 DLLEXPORT void concat(const QoreString *str, qore_size_t size, ExceptionSink *xsink);
00158
00160 DLLEXPORT void concatBase64(const char *buf, qore_size_t size);
00161
00163 DLLEXPORT void concatBase64(const BinaryNode *bin);
00164
00166 DLLEXPORT void concatBase64(const QoreString *str);
00167
00169
00173 DLLEXPORT BinaryNode *parseBase64(ExceptionSink *xsink) const;
00174
00176
00180 DLLEXPORT QoreString *parseBase64ToString(ExceptionSink *xsink) const;
00181
00183 DLLEXPORT void concatHex(const char *buf, qore_size_t size);
00184
00186 DLLEXPORT void concatHex(const BinaryNode *bin);
00187
00189 DLLEXPORT void concatHex(const QoreString *str);
00190
00192
00196 DLLEXPORT BinaryNode *parseHex(ExceptionSink *xsink) const;
00197
00199 DLLEXPORT void concat(const DateTime *d);
00200
00202 DLLEXPORT void concatISO8601DateTime(const DateTime *d);
00203
00205 DLLEXPORT void concat(const char *str);
00206
00208 DLLEXPORT void concat(const char *str, qore_size_t size);
00209
00211 DLLEXPORT void concat(const char c);
00212
00214
00219 DLLEXPORT int compareSoft(const QoreString *str, ExceptionSink *xsink) const;
00220
00222
00226 DLLEXPORT int compare(const QoreString *str) const;
00227
00229
00233 DLLEXPORT int compare(const char *str) const;
00234
00236 DLLEXPORT void terminate(qore_size_t size);
00237
00239
00241 DLLEXPORT int sprintf(const char *fmt, ...);
00242
00244
00246 DLLEXPORT int vsprintf(const char *fmt, va_list args);
00247
00249
00251 DLLEXPORT void take(char *str);
00252
00254 DLLEXPORT void take(char *str, const QoreEncoding *enc);
00256
00257 DLLEXPORT void take(char *str, qore_size_t size);
00258
00260 DLLEXPORT void take(char *str, qore_size_t size, const QoreEncoding *enc);
00261
00263 DLLEXPORT void takeAndTerminate(char *str, qore_size_t size);
00264
00266
00271 DLLEXPORT QoreString *convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const;
00272
00274
00277 DLLEXPORT char *giveBuffer();
00278
00280 DLLEXPORT void clear();
00281
00283
00285 DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char *str);
00286
00288
00293 DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString *str);
00294
00296
00298 DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString *str, ExceptionSink *xsink);
00299
00301
00305 DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink);
00306
00308
00313 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
00314
00316
00322 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *strn, ExceptionSink *xsink);
00323
00325
00330 DLLEXPORT QoreString *substr(qore_offset_t offset, ExceptionSink *xsink) const;
00331
00333
00339 DLLEXPORT QoreString *substr(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const;
00340
00342 DLLEXPORT qore_size_t chomp();
00343
00345 DLLEXPORT const QoreEncoding *getEncoding() const;
00346
00348 DLLEXPORT QoreString *copy() const;
00349
00351
00353 DLLEXPORT void tolwr();
00354
00356
00358 DLLEXPORT void toupr();
00359
00361 DLLEXPORT qore_size_t strlen() const;
00362
00364 DLLEXPORT const char *getBuffer() const;
00365
00366
00367
00368 DLLEXPORT void allocate(unsigned requested_size);
00369
00371 DLLEXPORT void addch(char c, unsigned times);
00372
00374
00380 DLLEXPORT void concatUTF8FromUnicode(unsigned code);
00381
00383
00387 DLLEXPORT int concatUnicode(unsigned code, ExceptionSink *xsink);
00388
00390
00394 DLLEXPORT int concatUnicode(unsigned code);
00395
00397
00400 DLLEXPORT QoreString *reverse() const;
00401
00403 DLLEXPORT void trim_trailing(const char *chars = 0);
00404
00406 DLLEXPORT void trim_leading(const char *chars = 0);
00407
00409 DLLEXPORT void trim(const char *chars = 0);
00410
00412 DLLEXPORT void trim_trailing(char c);
00413
00415 DLLEXPORT void trim_leading(char c);
00416
00418 DLLEXPORT void trim(char c);
00419
00421
00425 DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
00426
00428
00433 DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink *xsink) const;
00434
00435
00436 DLLLOCAL void concat(const QoreString *str);
00437
00438
00439 DLLLOCAL QoreString(struct qore_string_private *p);
00440 };
00441
00442 DLLEXPORT QoreString *checkEncoding(const QoreString *str, const QoreEncoding *enc, ExceptionSink *xsink);
00443
00445
00454 class TempString {
00455 private:
00456 QoreString *str;
00457
00459 TempString(const TempString &);
00460
00462 TempString & operator=(const TempString &);
00463
00465 void *operator new(size_t);
00466
00467 public:
00469 DLLLOCAL TempString(QoreString *s) {
00470 str = s;
00471 }
00472
00474 DLLLOCAL ~TempString() {
00475 delete str;
00476 }
00477
00479 DLLLOCAL QoreString *operator->(){ return str; };
00480
00482 DLLLOCAL QoreString *operator*() { return str; };
00483
00485 DLLLOCAL operator bool() const { return str != 0; }
00486
00488 DLLLOCAL QoreString *release() { QoreString *rv = str; str = 0; return rv; }
00489 };
00490
00492
00504 class TempEncodingHelper {
00505 private:
00506 QoreString *str;
00507 bool temp;
00508
00510 DLLLOCAL TempEncodingHelper(const TempEncodingHelper &);
00511
00513 DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper &);
00514
00516 DLLLOCAL void *operator new(size_t);
00517
00519 DLLLOCAL void discard_intern() {
00520 if (temp && str)
00521 delete str;
00522 }
00523
00525
00530 DLLLOCAL void set_intern(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) {
00531 if (s->getEncoding() != qe) {
00532 str = s->convertEncoding(qe, xsink);
00533 temp = true;
00534 }
00535 else {
00536 str = const_cast<QoreString *>(s);
00537 temp = false;
00538 }
00539 }
00540
00541 public:
00543
00548 DLLLOCAL TempEncodingHelper(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) {
00549 set_intern(s, qe, xsink);
00550 }
00551
00553 DLLLOCAL TempEncodingHelper() : str(0) {
00554 }
00555
00557 DLLLOCAL ~TempEncodingHelper() {
00558 discard_intern();
00559 }
00560
00562
00568 DLLLOCAL int set(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) {
00569 discard_intern();
00570
00571 set_intern(s, qe, xsink);
00572 return str != 0;
00573 }
00574
00576 DLLLOCAL bool is_temp() const {
00577 return temp;
00578 }
00579
00581 DLLLOCAL const QoreString *operator->(){ return str; };
00582
00584 DLLLOCAL const QoreString *operator*() { return str; };
00585
00587
00590 DLLLOCAL operator bool() const { return str != 0; }
00591
00593
00596 DLLLOCAL char *giveBuffer() {
00597 if (!str)
00598 return 0;
00599 if (temp)
00600 return str->giveBuffer();
00601 return strdup(str->getBuffer());
00602 }
00603 };
00604
00605 #endif
00606