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_QORESTRINGNODE_H
00026
00027 #define _QORE_QORESTRINGNODE_H
00028
00029 #include <qore/AbstractQoreNode.h>
00030 #include <qore/QoreString.h>
00031
00033
00039 class QoreStringNode : public SimpleValueQoreNode, public QoreString
00040 {
00041 private:
00043 DLLLOCAL QoreStringNode(QoreString *str);
00044
00046 DLLLOCAL QoreStringNode& operator=(const QoreStringNode&);
00047
00048 DLLLOCAL virtual bool getAsBoolImpl() const;
00049 DLLLOCAL virtual int getAsIntImpl() const;
00050 DLLLOCAL virtual int64 getAsBigIntImpl() const;
00051 DLLLOCAL virtual double getAsFloatImpl() const;
00052
00053 protected:
00055 DLLEXPORT virtual ~QoreStringNode();
00056
00057 public:
00059 DLLEXPORT QoreStringNode();
00060
00062
00066 DLLEXPORT QoreStringNode(const char *str, const QoreEncoding *enc = QCS_DEFAULT);
00067
00069
00072 DLLEXPORT QoreStringNode(const QoreString &str);
00073
00075
00078 DLLEXPORT QoreStringNode(const QoreStringNode &str);
00079
00081
00085 DLLEXPORT QoreStringNode(const std::string &str, const QoreEncoding *enc = QCS_DEFAULT);
00086
00087
00088 DLLEXPORT QoreStringNode(const BinaryNode *b);
00089
00091
00097 DLLEXPORT QoreStringNode(char *nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding *enc);
00098
00099
00100 DLLEXPORT QoreStringNode(const char *str, qore_size_t len, const QoreEncoding *new_qorecharset = QCS_DEFAULT);
00101
00102
00103 DLLEXPORT QoreStringNode(char c);
00104
00106
00112 DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const;
00113
00115
00122 DLLEXPORT QoreString *getAsString(bool &del, int format_offset, ExceptionSink *xsink) const;
00123
00125
00129 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
00130
00132
00135 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
00136
00138
00142 DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
00143
00145
00148 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
00149
00151 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00152
00154
00158 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00159
00161
00166 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00167
00169 DLLEXPORT virtual const char *getTypeName() const;
00170
00172
00177 DLLEXPORT QoreStringNode *convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const;
00178
00180
00185 DLLEXPORT QoreStringNode *substr(qore_offset_t offset, ExceptionSink *xsink) const;
00186
00188
00194 DLLEXPORT QoreStringNode *substr(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const;
00195
00197 DLLEXPORT QoreStringNode *reverse() const;
00198
00199
00200 DLLEXPORT QoreStringNode *copy() const;
00201
00203 DLLEXPORT static QoreStringNode *createAndConvertEncoding(const char *str, const QoreEncoding *from, const QoreEncoding *to, ExceptionSink *xsink);
00204
00206 DLLEXPORT QoreStringNode *parseBase64ToString(ExceptionSink *xsink) const;
00207
00209 DLLEXPORT QoreStringNode *stringRefSelf() const;
00210
00212 DLLLOCAL QoreStringNode(const char *str, const QoreEncoding *from, const QoreEncoding *to, ExceptionSink *xsink);
00213
00215 DLLLOCAL QoreStringNode(struct qore_string_private *p);
00216
00217
00218 DLLLOCAL static const char *getStaticTypeName()
00219 {
00220 return "string";
00221 }
00222 };
00223
00224 extern QoreStringNode *NullString;
00225
00227
00233 class QoreStringValueHelper {
00234 private:
00235 QoreString *str;
00236 bool del;
00237
00239 DLLLOCAL QoreStringValueHelper(const QoreStringValueHelper&);
00240
00242 DLLLOCAL QoreStringValueHelper& operator=(const QoreStringValueHelper&);
00243
00245 DLLLOCAL void* operator new(size_t);
00246
00247 public:
00249 DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n)
00250 {
00251 if (n) {
00252
00253 if (n->getType() == NT_STRING) {
00254 del = false;
00255 str = const_cast<QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
00256 }
00257 else
00258 str = n->getStringRepresentation(del);
00259 }
00260 else {
00261 str = NullString;
00262 del = false;
00263 }
00264 }
00265
00267
00279 DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n, const QoreEncoding *enc, ExceptionSink *xsink)
00280 {
00281 if (n) {
00282
00283 if (n->getType() == NT_STRING) {
00284 del = false;
00285 str = const_cast<QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
00286 }
00287 else
00288 str = n->getStringRepresentation(del);
00289 if (str->getEncoding() != enc) {
00290 QoreString *t = str->convertEncoding(enc, xsink);
00291 if (!t)
00292 return;
00293 if (del)
00294 delete str;
00295 str = t;
00296 del = true;
00297 }
00298 }
00299 else {
00300 str = NullString;
00301 del = false;
00302 }
00303 }
00304
00306 DLLLOCAL ~QoreStringValueHelper()
00307 {
00308 if (del)
00309 delete str;
00310 }
00311
00313
00316 DLLLOCAL const QoreString *operator->() { return str; }
00317
00319
00322 DLLLOCAL const QoreString *operator*() { return str; }
00323
00325
00328 DLLLOCAL QoreString *giveString()
00329 {
00330 if (!str)
00331 return 0;
00332 if (!del)
00333 return str->copy();
00334
00335 QoreString *rv = str;
00336 del = false;
00337 str = 0;
00338 return rv;
00339 }
00340
00342 DLLLOCAL bool is_temp() const
00343 {
00344 return del;
00345 }
00346 };
00347
00349
00356 class QoreStringNodeValueHelper {
00357 private:
00358 QoreStringNode *str;
00359 bool temp;
00360
00362 DLLLOCAL QoreStringNodeValueHelper(const QoreStringNodeValueHelper&);
00363
00365 DLLLOCAL QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&);
00366
00368 DLLLOCAL void* operator new(size_t);
00369
00370 public:
00371 DLLLOCAL QoreStringNodeValueHelper(const AbstractQoreNode *n)
00372 {
00373 if (!n) {
00374 str = NullString;
00375 temp = false;
00376 return;
00377 }
00378
00379 qore_type_t ntype = n->getType();
00380 if (ntype == NT_STRING) {
00381 str = const_cast<QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
00382 temp = false;
00383 }
00384 else {
00385 str = new QoreStringNode();
00386 n->getStringRepresentation(*(static_cast<QoreString *>(str)));
00387 temp = true;
00388 }
00389 }
00390
00392 DLLLOCAL ~QoreStringNodeValueHelper()
00393 {
00394 if (temp)
00395 str->deref();
00396 }
00397
00399
00402 DLLLOCAL const QoreStringNode *operator->() { return str; }
00403
00405
00408 DLLLOCAL const QoreStringNode *operator*() { return str; }
00409
00411
00415 DLLLOCAL QoreStringNode *getReferencedValue()
00416 {
00417 if (temp)
00418 temp = false;
00419 else if (str)
00420 str->ref();
00421 return str;
00422 }
00423 };
00424
00425 #include <qore/ReferenceHolder.h>
00426
00428
00431 typedef SimpleRefHolder<QoreStringNode> QoreStringNodeHolder;
00432
00433 extern QoreString NothingTypeString;
00434
00436
00445 class QoreNodeAsStringHelper {
00446 private:
00447 QoreString *str;
00448 bool del;
00449
00451 DLLLOCAL QoreNodeAsStringHelper(const QoreNodeAsStringHelper&);
00452
00454 DLLLOCAL QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&);
00455
00457 DLLLOCAL void* operator new(size_t);
00458
00459 public:
00461 DLLLOCAL QoreNodeAsStringHelper(const AbstractQoreNode *n, int format_offset, ExceptionSink *xsink)
00462 {
00463 if (n)
00464 str = n->getAsString(del, format_offset, xsink);
00465 else {
00466 str = &NothingTypeString;
00467 del = false;
00468 }
00469 }
00470
00472 DLLLOCAL ~QoreNodeAsStringHelper()
00473 {
00474 if (del)
00475 delete str;
00476 }
00477
00479
00482 DLLLOCAL const QoreString *operator->() { return str; }
00483
00485
00488 DLLLOCAL const QoreString *operator*() { return str; }
00489
00491
00494 DLLLOCAL QoreString *giveString()
00495 {
00496 if (!str)
00497 return 0;
00498 if (!del)
00499 return str->copy();
00500
00501 QoreString *rv = str;
00502 del = false;
00503 str = 0;
00504 return rv;
00505 }
00506 };
00507
00508 #endif