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
00026 #ifndef _QORE_QORESTRING_H
00027
00028 #define _QORE_QORESTRING_H
00029
00030 #include <stdarg.h>
00031
00032 #include <string>
00033
00034 class DateTime;
00035 class BinaryNode;
00036
00038
00042 class QoreString {
00043 protected:
00045 struct qore_string_private *priv;
00046
00047 DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, QoreString *extract = 0);
00048 DLLLOCAL void splice_simple(qore_size_t offset, qore_size_t length, const char *str, qore_size_t str_len, QoreString *extract = 0);
00049 DLLLOCAL void splice_complex(qore_offset_t offset, ExceptionSink *xsink, QoreString *extract = 0);
00050 DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink, QoreString *extract = 0);
00051 DLLLOCAL void splice_complex(qore_offset_t offset, qore_offset_t length, const QoreString *str, ExceptionSink *xsink, QoreString *extract = 0);
00052 DLLLOCAL int substr_simple(QoreString *str, qore_offset_t offset) const;
00053 DLLLOCAL int substr_simple(QoreString *str, qore_offset_t offset, qore_offset_t length) const;
00054 DLLLOCAL int substr_complex(QoreString *str, qore_offset_t offset, ExceptionSink *xsink) const;
00055 DLLLOCAL int substr_complex(QoreString *str, qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const;
00056
00057
00058
00059 DLLLOCAL void concat_reverse(QoreString *targ) const;
00060
00061 DLLLOCAL int snprintf(size_t size, const char *fmt, ...);
00062 DLLLOCAL int vsnprintf(size_t size, const char *fmt, va_list args);
00063 DLLLOCAL static int convert_encoding_intern(const char *src, qore_size_t src_len, const QoreEncoding *from, QoreString &targ, const QoreEncoding *to, ExceptionSink *xsink);
00064
00065 public:
00067 DLLEXPORT QoreString();
00068
00070 DLLEXPORT QoreString(bool b);
00071
00073 DLLEXPORT QoreString(const char *str);
00074
00076 DLLEXPORT QoreString(const char *str, const QoreEncoding *new_qorecharset);
00077
00079 DLLEXPORT QoreString(const QoreEncoding *new_qorecharset);
00080
00082 DLLEXPORT QoreString(const char *str, qore_size_t len, const QoreEncoding *new_qorecharset = QCS_DEFAULT);
00083
00085 DLLEXPORT QoreString(const std::string &str, const QoreEncoding *new_encoding = QCS_DEFAULT);
00086
00088 DLLEXPORT QoreString(char c);
00089
00091 DLLEXPORT QoreString(const QoreString &str);
00092
00094 DLLEXPORT QoreString(const QoreString *str);
00095
00097 DLLEXPORT QoreString(const QoreString *str, qore_size_t len);
00098
00100 DLLEXPORT QoreString(int64 i);
00101
00103 DLLEXPORT QoreString(double f);
00104
00106 DLLEXPORT QoreString(const DateTime *date);
00107
00109 DLLEXPORT QoreString(const BinaryNode *bin);
00110
00112 DLLEXPORT QoreString(char *nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding *enc);
00113
00115 DLLEXPORT ~QoreString();
00116
00118
00120 DLLEXPORT qore_size_t length() const;
00121
00123 DLLEXPORT void set(const char *str, const QoreEncoding *new_qorecharset = QCS_DEFAULT);
00124
00126 DLLEXPORT void set(const QoreString *str);
00127
00129 DLLEXPORT void set(const QoreString &str);
00130
00132 DLLEXPORT void concatAndHTMLEncode(const char *str);
00133
00135 DLLEXPORT void concatAndHTMLDecode(const QoreString *str);
00136
00138 DLLEXPORT void concatEscape(const QoreString *str, char c, char esc_char, ExceptionSink *xsink);
00139
00141 DLLEXPORT void concatEscape(const char *str, char c, char esc_char = '\\');
00142
00144 DLLEXPORT void concatAndHTMLEncode(const QoreString *, ExceptionSink *xsink);
00145
00147 DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink);
00148
00150
00155 DLLEXPORT void concat(const QoreString *str, qore_size_t size, ExceptionSink *xsink);
00156
00158 DLLEXPORT void concatBase64(const char *buf, qore_size_t size);
00159
00161 DLLEXPORT void concatBase64(const BinaryNode *bin);
00162
00164 DLLEXPORT void concatBase64(const QoreString *str);
00165
00167
00171 DLLEXPORT BinaryNode *parseBase64(ExceptionSink *xsink) const;
00172
00174
00178 DLLEXPORT QoreString *parseBase64ToString(ExceptionSink *xsink) const;
00179
00181 DLLEXPORT void concatHex(const char *buf, qore_size_t size);
00182
00184 DLLEXPORT void concatHex(const BinaryNode *bin);
00185
00187 DLLEXPORT void concatHex(const QoreString *str);
00188
00190
00194 DLLEXPORT BinaryNode *parseHex(ExceptionSink *xsink) const;
00195
00197 DLLEXPORT void concat(const DateTime *d);
00198
00200 DLLEXPORT void concatISO8601DateTime(const DateTime *d);
00201
00203 DLLEXPORT void concat(const char *str);
00204
00206 DLLEXPORT void concat(const char *str, qore_size_t size);
00207
00209 DLLEXPORT void concat(const char c);
00210
00212
00217 DLLEXPORT int compareSoft(const QoreString *str, ExceptionSink *xsink) const;
00218
00220
00224 DLLEXPORT int compare(const QoreString *str) const;
00225
00227
00231 DLLEXPORT int compare(const char *str) const;
00232
00234 DLLEXPORT void terminate(qore_size_t size);
00235
00237
00239 DLLEXPORT int sprintf(const char *fmt, ...);
00240
00242
00244 DLLEXPORT int vsprintf(const char *fmt, va_list args);
00245
00247
00249 DLLEXPORT void take(char *str);
00250
00252 DLLEXPORT void take(char *str, const QoreEncoding *enc);
00254
00255 DLLEXPORT void take(char *str, qore_size_t size);
00256
00258 DLLEXPORT void take(char *str, qore_size_t size, const QoreEncoding *enc);
00259
00261 DLLEXPORT void takeAndTerminate(char *str, qore_size_t size);
00262
00264 DLLEXPORT void takeAndTerminate(char *str, qore_size_t size, const QoreEncoding *enc);
00265
00267
00272 DLLEXPORT QoreString *convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const;
00273
00275
00278 DLLEXPORT char *giveBuffer();
00279
00281 DLLEXPORT void clear();
00282
00284
00286 DLLEXPORT void reset();
00287
00289
00291 DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char *str);
00292
00294
00299 DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString *str);
00300
00302
00304 DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const QoreString *str, ExceptionSink *xsink);
00305
00307
00311 DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink);
00312
00314
00319 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
00320
00322
00328 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *strn, ExceptionSink *xsink);
00329
00331
00337 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const QoreString &str, ExceptionSink *xsink);
00338
00340
00345 DLLEXPORT QoreString *extract(qore_offset_t offset, ExceptionSink *xsink);
00346
00348
00354 DLLEXPORT QoreString *extract(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
00355
00357
00364 DLLEXPORT QoreString *extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *strn, ExceptionSink *xsink);
00365
00367
00372 DLLEXPORT QoreString *substr(qore_offset_t offset, ExceptionSink *xsink) const;
00373
00375
00381 DLLEXPORT QoreString *substr(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const;
00382
00384 DLLEXPORT qore_size_t chomp();
00385
00387 DLLEXPORT const QoreEncoding *getEncoding() const;
00388
00390 DLLEXPORT QoreString *copy() const;
00391
00393
00395 DLLEXPORT void tolwr();
00396
00398
00400 DLLEXPORT void toupr();
00401
00403 DLLEXPORT qore_size_t strlen() const;
00404
00406 DLLEXPORT const char *getBuffer() const;
00407
00408
00409
00410 DLLEXPORT void allocate(unsigned requested_size);
00411
00413 DLLEXPORT void addch(char c, unsigned times);
00414
00416
00422 DLLEXPORT void concatUTF8FromUnicode(unsigned code);
00423
00425
00429 DLLEXPORT int concatUnicode(unsigned code, ExceptionSink *xsink);
00430
00432
00436 DLLEXPORT int concatUnicode(unsigned code);
00437
00439
00442 DLLEXPORT QoreString *reverse() const;
00443
00445 DLLEXPORT void trim_trailing(const char *chars = 0);
00446
00448 DLLEXPORT void trim_leading(const char *chars = 0);
00449
00451 DLLEXPORT void trim(const char *chars = 0);
00452
00454 DLLEXPORT void trim_trailing(char c);
00455
00457 DLLEXPORT void trim_single_trailing(char c);
00458
00460 DLLEXPORT void trim_leading(char c);
00461
00463 DLLEXPORT void trim_single_leading(char c);
00464
00466 DLLEXPORT void trim(char c);
00467
00469
00473 DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset = 0) const;
00474
00476
00481 DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink *xsink) const;
00482
00484 DLLEXPORT void prepend(const char *str);
00485
00487 DLLEXPORT void prepend(const char *str, qore_size_t size);
00488
00490 DLLEXPORT QoreString & operator=(const QoreString &other);
00491
00492
00493 DLLLOCAL void concat(const QoreString *str);
00494
00495
00496 DLLLOCAL QoreString(struct qore_string_private *p);
00497 };
00498
00499 DLLEXPORT QoreString *checkEncoding(const QoreString *str, const QoreEncoding *enc, ExceptionSink *xsink);
00500
00502
00511 class TempString {
00512 private:
00513 QoreString *str;
00514
00516 TempString(const TempString &);
00517
00519 TempString & operator=(const TempString &);
00520
00522 void *operator new(size_t);
00523
00524 public:
00526 DLLLOCAL TempString() : str(new QoreString) {
00527 }
00528
00530 DLLLOCAL TempString(const QoreEncoding *enc) : str(new QoreString(enc)) {
00531 }
00532
00534 DLLLOCAL TempString(QoreString *s) {
00535 str = s;
00536 }
00537
00539 DLLLOCAL ~TempString() {
00540 delete str;
00541 }
00542
00544 DLLLOCAL QoreString *operator->(){ return str; };
00545
00547 DLLLOCAL QoreString *operator*() { return str; };
00548
00550 DLLLOCAL operator bool() const { return str != 0; }
00551
00553 DLLLOCAL QoreString *release() { QoreString *rv = str; str = 0; return rv; }
00554 };
00555
00557
00569 class TempEncodingHelper {
00570 private:
00571 QoreString *str;
00572 bool temp;
00573
00575 DLLLOCAL TempEncodingHelper(const TempEncodingHelper &);
00576
00578 DLLLOCAL TempEncodingHelper& operator=(const TempEncodingHelper &);
00579
00581 DLLLOCAL void *operator new(size_t);
00582
00584 DLLLOCAL void discard_intern() {
00585 if (temp && str)
00586 delete str;
00587 }
00588
00590
00595 DLLLOCAL void set_intern(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) {
00596 if (s->getEncoding() != qe) {
00597 str = s->convertEncoding(qe, xsink);
00598 temp = true;
00599 }
00600 else {
00601 str = const_cast<QoreString *>(s);
00602 temp = false;
00603 }
00604 }
00605
00606 public:
00608
00613 DLLLOCAL TempEncodingHelper(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) {
00614 set_intern(s, qe, xsink);
00615 }
00616
00618 DLLLOCAL TempEncodingHelper() : str(0), temp(false) {
00619 }
00620
00622 DLLLOCAL ~TempEncodingHelper() {
00623 discard_intern();
00624 }
00625
00627
00636 DLLLOCAL int set(const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) {
00637 discard_intern();
00638
00639 set_intern(s, qe, xsink);
00640 return str != 0;
00641 }
00642
00644 DLLLOCAL bool is_temp() const {
00645 return temp;
00646 }
00647
00649 DLLLOCAL const QoreString *operator->(){ return str; };
00650
00652 DLLLOCAL const QoreString *operator*() { return str; };
00653
00655
00658 DLLLOCAL operator bool() const { return str != 0; }
00659
00661
00664 DLLLOCAL char *giveBuffer() {
00665 if (!str)
00666 return 0;
00667 if (temp)
00668 return str->giveBuffer();
00669 return strdup(str->getBuffer());
00670 }
00671 };
00672
00673 #endif
00674