Qore Programming Language - C/C++ Library  1.0.8
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 - 2021 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 <cstring>
42 
44 
51 private:
52  QoreStringNode(QoreString* str) = delete;
53  QoreStringNode& operator=(const QoreStringNode&) = delete;
54 
55  // note implemented; declared private here to probit them from being called
56  DLLLOCAL virtual bool getAsBoolImpl() const;
57  DLLLOCAL virtual int getAsIntImpl() const;
58  DLLLOCAL virtual int64 getAsBigIntImpl() const;
59  DLLLOCAL virtual double getAsFloatImpl() const;
60 
61 protected:
63  DLLEXPORT virtual ~QoreStringNode();
64 
65 public:
67  DLLEXPORT QoreStringNode();
68 
70 
74  DLLEXPORT QoreStringNode(const char* str, const QoreEncoding* enc = QCS_DEFAULT);
75 
77 
80  DLLEXPORT QoreStringNode(const QoreString& str);
81 
83 
86  DLLEXPORT QoreStringNode(const QoreStringNode& str);
87 
89 
93  DLLEXPORT QoreStringNode(const std::string& str, const QoreEncoding* enc = QCS_DEFAULT);
94 
95  // copies binary object and makes a base64-encoded string out of it
96  DLLEXPORT QoreStringNode(const BinaryNode* b);
97 
99  DLLEXPORT QoreStringNode(const BinaryNode* bin, size_t maxlinelen);
100 
102 
108  DLLEXPORT QoreStringNode(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
109 
111  DLLEXPORT QoreStringNode(const char* str, size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
112 
113  // creates a string from a single character
114  DLLEXPORT QoreStringNode(char c);
115 
117 
123  DLLEXPORT int getAsString(QoreString& str, int format_offset, ExceptionSink* xsink) const;
124 
126 
133  DLLEXPORT QoreString* getAsString(bool& del, int format_offset, ExceptionSink* xsink) const;
134 
136 
140  DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
141 
143 
146  DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
147 
149 
153  DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
154 
156 
159  DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
160 
162  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
163 
165 
169  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
170 
172 
177  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
178 
180  DLLEXPORT virtual const char* getTypeName() const;
181 
183 
188  DLLEXPORT QoreStringNode* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
189 
191 
196  DLLEXPORT QoreStringNode* substr(qore_offset_t offset, ExceptionSink* xsink) const;
197 
199 
205  DLLEXPORT QoreStringNode* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
206 
208  DLLEXPORT QoreStringNode* reverse() const;
209 
210  // copy function
211  DLLEXPORT QoreStringNode* copy() const;
212 
214  DLLEXPORT static QoreStringNode* createAndConvertEncoding(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
215 
217  DLLEXPORT QoreStringNode* parseBase64ToString(ExceptionSink* xsink) const;
218 
220 
225  DLLEXPORT QoreStringNode* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
226 
228  DLLEXPORT QoreStringNode* stringRefSelf() const;
229 
231 
236  DLLEXPORT QoreStringNode* extract(qore_offset_t offset, ExceptionSink* xsink);
237 
239 
246 
248 
256 
258  DLLLOCAL static const char* getStaticTypeName() {
259  return "string";
260  }
261 
263  DLLLOCAL static qore_type_t getStaticTypeCode() {
264  return NT_STRING;
265  }
266 
267  static const qore_type_t TYPE = NT_STRING;
268 
270  DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
271 
273  DLLLOCAL QoreStringNode(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
274 
276  DLLLOCAL QoreStringNode(struct qore_string_private* p);
277 };
278 
279 class QoreStringNodeMaker : public QoreStringNode {
280 public:
281  DLLEXPORT QoreStringNodeMaker(const char* fmt, ...);
282 
283 private:
284  QoreStringNodeMaker(const QoreStringNodeMaker& str) = delete;
285  QoreStringNodeMaker& operator=(const QoreStringNodeMaker&) = delete;
286 };
287 
288 extern QoreStringNode* NullString;
289 
291 
298 public:
300  DLLEXPORT QoreStringValueHelper(const QoreValue n);
301 
303 
315  DLLEXPORT QoreStringValueHelper(const QoreValue n, const QoreEncoding* enc, ExceptionSink* xsink);
316 
318  DLLEXPORT ~QoreStringValueHelper();
319 
321 
324  DLLEXPORT const QoreString* operator->();
325 
327 
330  DLLEXPORT const QoreString* operator*();
331 
333 
336  DLLEXPORT QoreString* giveString();
337 
339 
341  DLLEXPORT char* giveBuffer();
342 
344  DLLEXPORT bool is_temp() const;
345 
346 private:
347  QoreString* str;
348  bool del;
349 
351  QoreStringValueHelper& operator=(const QoreStringValueHelper&) = delete;
352  void* operator new(size_t) = delete;
353 
355  DLLEXPORT void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = nullptr);
356 };
357 
359 
367 public:
368  DLLEXPORT QoreStringNodeValueHelper(const QoreValue n);
369 
371 
383  DLLEXPORT QoreStringNodeValueHelper(const QoreValue n, const QoreEncoding* enc, ExceptionSink* xsink);
384 
386  DLLEXPORT ~QoreStringNodeValueHelper();
387 
389 
392  DLLEXPORT const QoreStringNode* operator->();
393 
395 
398  DLLEXPORT const QoreStringNode* operator*();
399 
401 
405  DLLEXPORT QoreStringNode* getReferencedValue();
406 
408  DLLEXPORT bool is_temp() const;
409 
410 private:
411  QoreStringNode* str;
412  bool del;
413 
415  QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&) = delete;
416  void* operator new(size_t) = delete;
417 
419  DLLEXPORT void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = nullptr);
420 };
421 
422 #include <qore/ReferenceHolder.h>
423 
425 
429 
430 extern QoreString NothingTypeString;
431 
433 
443 public:
445  DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode* n, int format_offset, ExceptionSink* xsink);
446 
448  DLLEXPORT QoreNodeAsStringHelper(const QoreValue n, int format_offset, ExceptionSink* xsink);
449 
451  DLLEXPORT ~QoreNodeAsStringHelper();
452 
454 
457  DLLEXPORT const QoreString* operator->();
458 
460 
463  DLLEXPORT const QoreString* operator*();
464 
466 
469  DLLEXPORT QoreString* giveString();
470 
471 private:
472  QoreString* str;
473  bool del;
474 
476  QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&) = delete;
477  void* operator new(size_t) = delete;
478 };
479 
480 #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:83
DLLEXPORT const QoreStringNode * operator->()
returns the object being managed
DLLEXPORT QoreStringNode * reverse() const
return a QoreStringNode with the characters reversed
DLLEXPORT char * giveBuffer()
returns a char* string that the caller owns and must free()
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
DLLEXPORT const QoreStringNode * operator*()
returns the object being managed
DLLEXPORT bool is_temp() const
returns true if the reference being managed is temporary
safely manages the return values to AbstractQoreNode::getAsString(), stack only, cannot be dynamicall...
Definition: QoreStringNode.h:442
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
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
DLLEXPORT const QoreString * operator->()
returns the object being managed
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
DLLEXPORT QoreStringNode * getReferencedValue()
returns a referenced value - the caller will own the reference
DLLEXPORT const QoreString * operator*()
returns the object being managed
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
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...
DLLEXPORT QoreStringValueHelper(const QoreValue n)
creates the object and acquires a pointer to the QoreString representation of the QoreValue passed ...
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:297
DLLEXPORT QoreStringNode()
creates an empty string and assigns the default encoding QCS_DEFAULT
DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode *n, int format_offset, ExceptionSink *xsink)
makes the call to AbstractQoreNode::getAsString() and manages the return values
DLLEXPORT size_t length() const
returns the number of characters (not bytes) in the 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...
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
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:48
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
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
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:260
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
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:366
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreStringNode.h:263
DLLEXPORT QoreString * giveString()
returns a copy of the QoreString that the caller owns
DLLEXPORT const QoreString * operator*()
returns the object being managed
DLLEXPORT const QoreString * operator->()
returns the object being managed
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:70
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
base class for simple value types
Definition: AbstractQoreNode.h:372
DLLEXPORT ~QoreStringValueHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
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 ...
DLLEXPORT bool is_temp() const
returns true if the pointer being managed is temporary
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreStringNode.h:258
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object, the caller owns the reference count
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
holds arbitrary binary data
Definition: BinaryNode.h:41