Qore Programming Language - C/C++ Library  0.8.13.4
QoreStringNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreStringNode.h
4 
5  QoreStringNode Class Definition
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2016 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_QORESTRINGNODE_H
35 
36 #define _QORE_QORESTRINGNODE_H
37 
38 #include <qore/AbstractQoreNode.h>
39 #include <qore/QoreString.h>
40 
41 #include <string.h>
42 
44 
51 private:
53  DLLLOCAL QoreStringNode(QoreString* str);
54 
56  DLLLOCAL QoreStringNode& operator=(const QoreStringNode&);
57 
58  DLLLOCAL virtual bool getAsBoolImpl() const;
59  DLLLOCAL virtual int getAsIntImpl() const;
60  DLLLOCAL virtual int64 getAsBigIntImpl() const;
61  DLLLOCAL virtual double getAsFloatImpl() const;
62 
63 protected:
65  DLLEXPORT virtual ~QoreStringNode();
66 
67 public:
69  DLLEXPORT QoreStringNode();
70 
72 
76  DLLEXPORT QoreStringNode(const char* str, const QoreEncoding* enc = QCS_DEFAULT);
77 
79 
82  DLLEXPORT QoreStringNode(const QoreString& str);
83 
85 
88  DLLEXPORT QoreStringNode(const QoreStringNode& str);
89 
91 
95  DLLEXPORT QoreStringNode(const std::string& str, const QoreEncoding* enc = QCS_DEFAULT);
96 
97  // copies binary object and makes a base64-encoded string out of it
98  DLLEXPORT QoreStringNode(const BinaryNode* b);
99 
101  DLLEXPORT QoreStringNode(const BinaryNode* bin, qore_size_t maxlinelen);
102 
104 
110  DLLEXPORT QoreStringNode(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
111 
113  DLLEXPORT QoreStringNode(const char* str, qore_size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
114 
115  // creates a string from a single character
116  DLLEXPORT QoreStringNode(char c);
117 
119 
125  DLLEXPORT int getAsString(QoreString& str, int format_offset, ExceptionSink* xsink) const;
126 
128 
135  DLLEXPORT QoreString* getAsString(bool& del, int format_offset, ExceptionSink* xsink) const;
136 
138 
142  DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
143 
145 
148  DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
149 
151 
155  DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
156 
158 
161  DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
162 
164  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
165 
167 
171  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
172 
174 
179  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
180 
182  DLLEXPORT virtual const char* getTypeName() const;
183 
185 
190  DLLEXPORT QoreStringNode* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
191 
193 
198  DLLEXPORT QoreStringNode* substr(qore_offset_t offset, ExceptionSink* xsink) const;
199 
201 
207  DLLEXPORT QoreStringNode* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
208 
210  DLLEXPORT QoreStringNode* reverse() const;
211 
212  // copy function
213  DLLEXPORT QoreStringNode* copy() const;
214 
216  DLLEXPORT static QoreStringNode* createAndConvertEncoding(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
217 
219  DLLEXPORT QoreStringNode* parseBase64ToString(ExceptionSink* xsink) const;
220 
222 
227  DLLEXPORT QoreStringNode* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
228 
230  DLLEXPORT QoreStringNode* stringRefSelf() const;
231 
233  DLLLOCAL QoreStringNode(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
234 
236 
241  DLLEXPORT QoreStringNode* extract(qore_offset_t offset, ExceptionSink* xsink);
242 
244 
250  DLLEXPORT QoreStringNode* extract(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
251 
253 
260  DLLEXPORT QoreStringNode* extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
261 
263  DLLLOCAL QoreStringNode(struct qore_string_private* p);
264 
266  DLLLOCAL static const char* getStaticTypeName() {
267  return "string";
268  }
269 
271  DLLLOCAL static qore_type_t getStaticTypeCode() {
272  return NT_STRING;
273  }
274 
275  static const qore_type_t TYPE = NT_STRING;
276 
278  DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
279 };
280 
281 class QoreStringNodeMaker : public QoreStringNode {
282 private:
284  DLLLOCAL QoreStringNodeMaker(const QoreStringNodeMaker& str);
285 
287  DLLLOCAL QoreStringNodeMaker& operator=(const QoreStringNodeMaker&);
288 
289 public:
290  DLLEXPORT QoreStringNodeMaker(const char* fmt, ...);
291 };
292 
293 extern QoreStringNode* NullString;
294 
296 
303 protected:
304  QoreString* str;
305  bool del;
306 
308  DLLLOCAL QoreStringValueHelper(const QoreStringValueHelper&); // not implemented
309 
311  DLLLOCAL QoreStringValueHelper& operator=(const QoreStringValueHelper&); // not implemented
312 
314  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
315 
317  DLLLOCAL void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = 0);
318 
319 public:
321  DLLEXPORT QoreStringValueHelper(const AbstractQoreNode* n);
322 
324  DLLEXPORT explicit QoreStringValueHelper(const QoreValue& n);
325 
327 
339  DLLEXPORT QoreStringValueHelper(const AbstractQoreNode* n, const QoreEncoding* enc, ExceptionSink* xsink);
340 
342  DLLEXPORT QoreStringValueHelper(const QoreValue& n, const QoreEncoding* enc, ExceptionSink* xsink);
343 
345  DLLLOCAL ~QoreStringValueHelper() {
346  if (del)
347  delete str;
348  }
349 
351 
354  DLLLOCAL const QoreString* operator->() { return str; }
355 
357 
360  DLLLOCAL const QoreString* operator*() { return str; }
361 
363 
366  DLLLOCAL QoreString* giveString() {
367  if (!str)
368  return 0;
369  if (!del)
370  return str->copy();
371 
372  QoreString* rv = str;
373  del = false;
374  str = 0;
375  return rv;
376  }
377 
379 
381  DLLLOCAL char* giveBuffer() {
382  if (!str)
383  return 0;
384  if (!del)
385  return strdup(str->getBuffer());
386  char* rv = str->giveBuffer();
387  delete str;
388  del = false;
389  str = 0;
390  return rv;
391  }
392 
394  DLLLOCAL bool is_temp() const {
395  return del;
396  }
397 };
398 
400 
408 private:
409  QoreStringNode* str;
410  bool del;
411 
414 
416  DLLLOCAL QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&);
417 
419  DLLLOCAL void* operator new(size_t);
420 
422  DLLLOCAL void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = 0);
423 
424 public:
425  DLLEXPORT QoreStringNodeValueHelper(const AbstractQoreNode* n);
426 
427  DLLEXPORT QoreStringNodeValueHelper(const QoreValue& n);
428 
430 
442  DLLEXPORT QoreStringNodeValueHelper(const AbstractQoreNode* n, const QoreEncoding* enc, ExceptionSink* xsink);
443 
445  DLLEXPORT QoreStringNodeValueHelper(const QoreValue& n, const QoreEncoding* enc, ExceptionSink* xsink);
446 
448  DLLEXPORT ~QoreStringNodeValueHelper();
449 
451 
454  DLLLOCAL const QoreStringNode* operator->() { return str; }
455 
457 
460  DLLLOCAL const QoreStringNode* operator*() { return str; }
461 
463 
467  DLLEXPORT QoreStringNode* getReferencedValue();
468 
470  DLLLOCAL bool is_temp() const {
471  return del;
472  }
473 };
474 
475 #include <qore/ReferenceHolder.h>
476 
478 
482 
483 extern QoreString NothingTypeString;
484 
486 
496 private:
497  QoreString* str;
498  bool del;
499 
501  DLLLOCAL QoreNodeAsStringHelper(const QoreNodeAsStringHelper&); // not implemented
502 
504  DLLLOCAL QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&); // not implemented
505 
507  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
508 
509 public:
511  DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode* n, int format_offset, ExceptionSink* xsink);
512 
514  DLLEXPORT QoreNodeAsStringHelper(const QoreValue n, int format_offset, ExceptionSink* xsink);
515 
517  DLLEXPORT ~QoreNodeAsStringHelper();
518 
520 
523  DLLLOCAL const QoreString* operator->() { return str; }
524 
526 
529  DLLLOCAL const QoreString* operator*() { return str; }
530 
532 
535  DLLEXPORT QoreString* giveString();
536 };
537 
538 #endif
DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const
concatenates the string data in double quotes to an existing QoreString
virtual DLLEXPORT ~QoreStringNode()
destructor only called when references = 0, use deref() instead
defines string encoding functions in Qore
Definition: QoreEncoding.h:85
DLLEXPORT QoreStringNode * reverse() const
return a QoreStringNode with the characters reversed
DLLEXPORT QoreStringNode * stringRefSelf() const
references the object and returns a non-const pointer to "this"
static DLLEXPORT QoreStringNode * createAndConvertEncoding(const char *str, const QoreEncoding *from, const QoreEncoding *to, ExceptionSink *xsink)
creates a new QoreStringNode from a string and converts its encoding
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
safely manages the return values to AbstractQoreNode::getAsString(), stack only, cannot be dynamicall...
Definition: QoreStringNode.h:495
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
DLLEXPORT char * giveBuffer()
returns the character buffer and leaves the QoreString empty, the caller owns the memory returned (mu...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:74
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
DLLEXPORT const char * getBuffer() const
returns the string&#39;s buffer; this data should not be changed
DLLEXPORT QoreStringNode * substr(qore_offset_t offset, ExceptionSink *xsink) const
returns a new string consisting of all the characters from the current string starting with character...
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:302
DLLEXPORT QoreStringNode()
creates an empty string and assigns the default encoding QCS_DEFAULT
DLLEXPORT QoreStringNode * convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const
converts the encoding of the string to the specified encoding, returns 0 if an error occurs...
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:45
DLLEXPORT QoreStringNode * extract(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset" and returns a string of the characte...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:117
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values for container types) without type o...
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the current string and sets del to false
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
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:241
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:77
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a QoreS...
Definition: QoreStringNode.h:407
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreStringNode.h:271
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:71
base class for simple value types
Definition: AbstractQoreNode.h:434
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values for container types) with possible ...
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this string
DLLEXPORT QoreStringNode * parseBase64ToString(ExceptionSink *xsink) const
parses the string as a base64-encoded binary and returns the decoded value as a QoreStringNode ...
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreStringNode.h:266
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object, the caller owns the reference count
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT qore_size_t length() const
returns the number of characters (not bytes) in the string