Qore Programming Language - C/C++ Library  0.8.12.3
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 - 2015 David Nichols
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 
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 temp;
411 
414 
416  DLLLOCAL QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&);
417 
419  DLLLOCAL void* operator new(size_t);
420 
421 public:
422  DLLEXPORT QoreStringNodeValueHelper(const AbstractQoreNode* n);
423 
424  DLLEXPORT QoreStringNodeValueHelper(const QoreValue& n);
425 
427  DLLEXPORT ~QoreStringNodeValueHelper();
428 
430 
433  DLLLOCAL const QoreStringNode* operator->() { return str; }
434 
436 
439  DLLLOCAL const QoreStringNode* operator*() { return str; }
440 
442 
446  DLLEXPORT QoreStringNode* getReferencedValue();
447 };
448 
449 #include <qore/ReferenceHolder.h>
450 
452 
456 
457 extern QoreString NothingTypeString;
458 
460 
470 private:
471  QoreString* str;
472  bool del;
473 
475  DLLLOCAL QoreNodeAsStringHelper(const QoreNodeAsStringHelper&); // not implemented
476 
478  DLLLOCAL QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&); // not implemented
479 
481  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
482 
483 public:
485  DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode* n, int format_offset, ExceptionSink* xsink);
486 
488  DLLEXPORT QoreNodeAsStringHelper(const QoreValue n, int format_offset, ExceptionSink* xsink);
489 
491  DLLEXPORT ~QoreNodeAsStringHelper();
492 
494 
497  DLLLOCAL const QoreString* operator->() { return str; }
498 
500 
503  DLLLOCAL const QoreString* operator*() { return str; }
504 
506 
509  DLLEXPORT QoreString* giveString();
510 };
511 
512 #endif
virtual DLLEXPORT ~QoreStringNode()
destructor only called when references = 0, use deref() instead
DLLLOCAL QoreString * giveString()
returns a copy of the QoreString that the caller owns
Definition: QoreStringNode.h:366
DLLLOCAL const QoreStringNode * operator->()
returns the object being managed
Definition: QoreStringNode.h:433
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...
defines string encoding functions in Qore
Definition: QoreEncoding.h:85
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
DLLLOCAL const QoreString * operator*()
returns the object being managed
Definition: QoreStringNode.h:503
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:469
DLLEXPORT ~QoreStringNodeValueHelper()
destroys the object and dereferences the QoreStringNode if it is a temporary pointer ...
DLLEXPORT QoreString * giveString()
returns a copy of the QoreString that the caller owns
DLLLOCAL QoreStringValueHelper & operator=(const QoreStringValueHelper &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
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:55
DLLLOCAL const QoreString * operator->()
returns the object being managed
Definition: QoreStringNode.h:497
DLLEXPORT QoreStringNode * reverse() const
return a QoreStringNode with the characters reversed
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:71
DLLEXPORT QoreStringNode * getReferencedValue()
returns a referenced value - the caller will own the reference
DLLLOCAL const QoreString * operator*()
returns the object being managed
Definition: QoreStringNode.h:360
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 QoreString * getStringRepresentation(bool &del) const
returns the current string and sets del to false
DLLLOCAL bool is_temp() const
returns true if the pointer being managed is temporary
Definition: QoreStringNode.h:394
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT qore_size_t length() const
returns the number of characters (not bytes) in the string
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
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...
DLLLOCAL char * giveBuffer()
returns a char* string that the caller owns and must free()
Definition: QoreStringNode.h:381
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:302
DLLEXPORT QoreStringNode * parseBase64ToString(ExceptionSink *xsink) const
parses the string as a base64-encoded binary and returns the decoded value as a QoreStringNode ...
DLLEXPORT QoreStringNode()
creates an empty string and assigns the default encoding QCS_DEFAULT
DLLLOCAL void setup(ExceptionSink *xsink, const QoreValue n, const QoreEncoding *enc=0)
sets up the object / common initialization
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this string
DLLLOCAL ~QoreStringValueHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
Definition: QoreStringNode.h:345
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...
DLLLOCAL const QoreString * operator->()
returns the object being managed
Definition: QoreStringNode.h:354
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const
concatenates the string data in double quotes to an existing QoreString
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:111
DLLEXPORT QoreStringNode * stringRefSelf() const
references the object and returns a non-const pointer to "this"
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:228
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:74
DLLEXPORT ~QoreNodeAsStringHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
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:68
DLLLOCAL const QoreStringNode * operator*()
returns the object being managed
Definition: QoreStringNode.h:439
DLLLOCAL QoreStringValueHelper(const QoreStringValueHelper &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
base class for simple value types
Definition: AbstractQoreNode.h:435
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 AbstractQoreNode * realCopy() const
returns a copy of the object, the caller owns the reference count
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreStringNode.h:266
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT const char * getBuffer() const
returns the string's buffer; this data should not be changed