Qore Programming Language 0.8.8

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 2003 - 2013 David Nichols
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef _QORE_QORESTRINGNODE_H
27
28 #define _QORE_QORESTRINGNODE_H
29
30 #include <qore/AbstractQoreNode.h>
31 #include <qore/QoreString.h>
32
34
40 class QoreStringNode : public SimpleValueQoreNode, public QoreString {
41 private:
43 DLLLOCAL QoreStringNode(QoreString *str);
44
46 DLLLOCAL QoreStringNode& operator=(const QoreStringNode&);
47
48 DLLLOCAL virtual bool getAsBoolImpl() const;
49 DLLLOCAL virtual int getAsIntImpl() const;
50 DLLLOCAL virtual int64 getAsBigIntImpl() const;
51 DLLLOCAL virtual double getAsFloatImpl() const;
52
53 protected:
55 DLLEXPORT virtual ~QoreStringNode();
56
57 public:
59 DLLEXPORT QoreStringNode();
60
62
66 DLLEXPORT QoreStringNode(const char *str, const QoreEncoding *enc = QCS_DEFAULT);
67
69
72 DLLEXPORT QoreStringNode(const QoreString &str);
73
75
78 DLLEXPORT QoreStringNode(const QoreStringNode &str);
79
81
85 DLLEXPORT QoreStringNode(const std::string &str, const QoreEncoding *enc = QCS_DEFAULT);
86
87 // copies binary object and makes a base64-encoded string out of it
88 DLLEXPORT QoreStringNode(const BinaryNode *b);
89
91 DLLEXPORT QoreStringNode(const BinaryNode *bin, qore_size_t maxlinelen);
92
94
100 DLLEXPORT QoreStringNode(char *nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding *enc);
101
103 DLLEXPORT QoreStringNode(const char *str, qore_size_t len, const QoreEncoding *new_qorecharset = QCS_DEFAULT);
104
105 // creates a string from a single character
106 DLLEXPORT QoreStringNode(char c);
107
109
115 DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const;
116
118
125 DLLEXPORT QoreString *getAsString(bool &del, int format_offset, ExceptionSink *xsink) const;
126
128
132 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
133
135
138 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
139
141
145 DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
146
148
151 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
152
154 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
155
157
161 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
162
164
169 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
170
172 DLLEXPORT virtual const char *getTypeName() const;
173
175
180 DLLEXPORT QoreStringNode *convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const;
181
183
188 DLLEXPORT QoreStringNode *substr(qore_offset_t offset, ExceptionSink *xsink) const;
189
191
197 DLLEXPORT QoreStringNode *substr(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const;
198
200 DLLEXPORT QoreStringNode *reverse() const;
201
202 // copy function
203 DLLEXPORT QoreStringNode *copy() const;
204
206 DLLEXPORT static QoreStringNode *createAndConvertEncoding(const char *str, const QoreEncoding *from, const QoreEncoding *to, ExceptionSink *xsink);
207
209 DLLEXPORT QoreStringNode *parseBase64ToString(ExceptionSink *xsink) const;
210
212
217 DLLEXPORT QoreStringNode* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
218
220 DLLEXPORT QoreStringNode *stringRefSelf() const;
221
223 DLLLOCAL QoreStringNode(const char *str, const QoreEncoding *from, const QoreEncoding *to, ExceptionSink *xsink);
224
226
231 DLLEXPORT QoreStringNode *extract(qore_offset_t offset, ExceptionSink *xsink);
232
234
240 DLLEXPORT QoreStringNode *extract(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
241
243
250 DLLEXPORT QoreStringNode *extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *strn, ExceptionSink *xsink);
251
253 DLLLOCAL QoreStringNode(struct qore_string_private *p);
254
256 DLLLOCAL static const char *getStaticTypeName() {
257 return "string";
258 }
259
261 DLLLOCAL static qore_type_t getStaticTypeCode() {
262 return NT_STRING;
263 }
264
266 DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
267 };
268
269 class QoreStringNodeMaker : public QoreStringNode {
270 private:
272 DLLLOCAL QoreStringNodeMaker(const QoreStringNodeMaker& str);
273
275 DLLLOCAL QoreStringNodeMaker& operator=(const QoreStringNodeMaker&);
276
277 public:
278 DLLEXPORT QoreStringNodeMaker(const char* fmt, ...);
279 };
280
281 extern QoreStringNode *NullString;
282
284
290 class QoreStringValueHelper {
291 private:
292 QoreString *str;
293 bool del;
294
296 DLLLOCAL QoreStringValueHelper(const QoreStringValueHelper&); // not implemented
297
299 DLLLOCAL QoreStringValueHelper& operator=(const QoreStringValueHelper&); // not implemented
300
302 DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
303
304 public:
306 DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n) {
307 if (n) {
308 //optimization to remove the need for a virtual function call in the most common case
309 if (n->getType() == NT_STRING) {
310 del = false;
311 str = const_cast<QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
312 }
313 else
314 str = n->getStringRepresentation(del);
315 }
316 else {
317 str = NullString;
318 del = false;
319 }
320 }
321
323
335 DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n, const QoreEncoding *enc, ExceptionSink *xsink) {
336 if (n) {
337 //optimization to remove the need for a virtual function call in the most common case
338 if (n->getType() == NT_STRING) {
339 del = false;
340 str = const_cast<QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
341 }
342 else
343 str = n->getStringRepresentation(del);
344 if (str->getEncoding() != enc) {
345 QoreString *t = str->convertEncoding(enc, xsink);
346 if (!t)
347 return;
348 if (del)
349 delete str;
350 str = t;
351 del = true;
352 }
353 }
354 else {
355 str = NullString;
356 del = false;
357 }
358 }
359
361 DLLLOCAL ~QoreStringValueHelper() {
362 if (del)
363 delete str;
364 }
365
367
370 DLLLOCAL const QoreString *operator->() { return str; }
371
373
376 DLLLOCAL const QoreString *operator*() { return str; }
377
379
382 DLLLOCAL QoreString *giveString() {
383 if (!str)
384 return 0;
385 if (!del)
386 return str->copy();
387
388 QoreString *rv = str;
389 del = false;
390 str = 0;
391 return rv;
392 }
393
395 DLLLOCAL bool is_temp() const {
396 return del;
397 }
398 };
399
401
408 class QoreStringNodeValueHelper {
409 private:
410 QoreStringNode *str;
411 bool temp;
412
414 DLLLOCAL QoreStringNodeValueHelper(const QoreStringNodeValueHelper&);
415
417 DLLLOCAL QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&);
418
420 DLLLOCAL void* operator new(size_t);
421
422 public:
423 DLLLOCAL QoreStringNodeValueHelper(const AbstractQoreNode *n) {
424 if (!n) {
425 str = NullString;
426 temp = false;
427 return;
428 }
429
430 qore_type_t ntype = n->getType();
431 if (ntype == NT_STRING) {
432 str = const_cast<QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
433 temp = false;
434 }
435 else {
436 str = new QoreStringNode();
437 n->getStringRepresentation(*(static_cast<QoreString *>(str)));
438 temp = true;
439 }
440 }
441
443 DLLLOCAL ~QoreStringNodeValueHelper() {
444 if (temp)
445 str->deref();
446 }
447
449
452 DLLLOCAL const QoreStringNode *operator->() { return str; }
453
455
458 DLLLOCAL const QoreStringNode *operator*() { return str; }
459
461
465 DLLLOCAL QoreStringNode *getReferencedValue() {
466 if (temp)
467 temp = false;
468 else if (str)
469 str->ref();
470 return str;
471 }
472 };
473
474 #include <qore/ReferenceHolder.h>
475
477
480 typedef SimpleRefHolder<QoreStringNode> QoreStringNodeHolder;
481
482 extern QoreString NothingTypeString;
483
485
494 class QoreNodeAsStringHelper {
495 private:
496 QoreString *str;
497 bool del;
498
500 DLLLOCAL QoreNodeAsStringHelper(const QoreNodeAsStringHelper&); // not implemented
501
503 DLLLOCAL QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&); // not implemented
504
506 DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
507
508 public:
510 DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode *n, int format_offset, ExceptionSink *xsink);
511
513 DLLLOCAL ~QoreNodeAsStringHelper() {
514 if (del)
515 delete str;
516 }
517
519
522 DLLLOCAL const QoreString *operator->() { return str; }
523
525
528 DLLLOCAL const QoreString *operator*() { return str; }
529
531
534 DLLLOCAL QoreString *giveString() {
535 if (!str)
536 return 0;
537 if (!del)
538 return str->copy();
539
540 QoreString *rv = str;
541 del = false;
542 str = 0;
543 return rv;
544 }
545 };
546
547 #endif
QoreStringNode::~QoreStringNode
virtual DLLEXPORT ~QoreStringNode()
destructor only called when references = 0, use deref() instead
QoreStringValueHelper::giveString
DLLLOCAL QoreString * giveString()
returns a copy of the QoreString that the caller owns
Definition: QoreStringNode.h:382
QoreStringNodeValueHelper::operator->
DLLLOCAL const QoreStringNode * operator->()
returns the object being managed
Definition: QoreStringNode.h:452
QoreStringNode::substr
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...
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:72
QoreStringNode::createAndConvertEncoding
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
QoreNodeAsStringHelper::operator*
DLLLOCAL const QoreString * operator*()
returns the object being managed
Definition: QoreStringNode.h:528
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
QoreNodeAsStringHelper
safely manages the return values to AbstractQoreNode::getAsString(), stack only, cannot be dynamicall...
Definition: QoreStringNode.h:494
QoreStringValueHelper::QoreStringValueHelper
DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n, const QoreEncoding *enc, ExceptionSink *xsink)
gets the QoreString representation and ensures that it&#39;s in the desired encoding
Definition: QoreStringNode.h:335
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:85
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
QoreNodeAsStringHelper::operator->
DLLLOCAL const QoreString * operator->()
returns the object being managed
Definition: QoreStringNode.h:522
QoreStringNode::reverse
DLLEXPORT QoreStringNode * reverse() const
return a QoreStringNode with the characters reversed
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:61
AbstractQoreNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the value of the type converted to a string, default implementation: returns the empty string...
qore_offset_t
long qore_offset_t
used for offsets that could be negative
Definition: common.h:64
QoreStringValueHelper::operator*
DLLLOCAL const QoreString * operator*()
returns the object being managed
Definition: QoreStringNode.h:376
QoreStringNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality (&quot;deep compare&quot; including all contained values for container types) with possible ...
QoreStringNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the current string and sets del to false
QoreStringValueHelper::is_temp
DLLLOCAL bool is_temp() const
returns true if the pointer being managed is temporary
Definition: QoreStringNode.h:395
QoreStringNodeValueHelper::getReferencedValue
DLLLOCAL QoreStringNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: QoreStringNode.h:465
qore_type_t
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:58
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:42
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
QoreString::convertEncoding
DLLEXPORT QoreString * convertEncoding(const QoreEncoding *nccs, ExceptionSink *xsink) const
converts the encoding of the string to the specified encoding, returns 0 if an error occurs...
QoreStringNodeValueHelper::~QoreStringNodeValueHelper
DLLLOCAL ~QoreStringNodeValueHelper()
destroys the object and dereferences the QoreStringNode if it is a temporary pointer ...
Definition: QoreStringNode.h:443
QoreString::length
DLLEXPORT qore_size_t length() const
returns the number of characters (not bytes) in the string
QoreStringNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreStringNode::convertEncoding
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...
QoreStringValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:290
QoreStringNode::parseBase64ToString
DLLEXPORT QoreStringNode * parseBase64ToString(ExceptionSink *xsink) const
parses the string as a base64-encoded binary and returns the decoded value as a QoreStringNode ...
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode()
creates an empty string and assigns the default encoding QCS_DEFAULT
QoreStringNode::getDateTimeRepresentation
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this string
QoreStringValueHelper::~QoreStringValueHelper
DLLLOCAL ~QoreStringValueHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
Definition: QoreStringNode.h:361
QoreStringValueHelper::QoreStringValueHelper
DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n)
creates the object and acquires a pointer to the QoreString representation of the AbstractQoreNode pa...
Definition: QoreStringNode.h:306
QoreString::getEncoding
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding for the string
NT_STRING
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:37
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
QoreStringNode::extract
DLLEXPORT QoreStringNode * extract(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position &quot;offset&quot; and returns a string of the characte...
QoreStringValueHelper::operator->
DLLLOCAL const QoreString * operator->()
returns the object being managed
Definition: QoreStringNode.h:370
QoreString::copy
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
QoreStringNode::getAsString
DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const
concatenates the string data in double quotes to an existing QoreString
SimpleRefHolder
manages a reference count of a pointer to a class that takes a simple &quot;deref()&quot; call with no argument...
Definition: ReferenceHolder.h:103
QoreStringNode::stringRefSelf
DLLEXPORT QoreStringNode * stringRefSelf() const
references the object and returns a non-const pointer to &quot;this&quot;
QoreStringNode::parseInit
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
QoreStringNodeValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a QoreS...
Definition: QoreStringNode.h:408
QoreStringNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreStringNode.h:261
AbstractQoreNode::getType
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:286
QoreNodeAsStringHelper::giveString
DLLLOCAL QoreString * giveString()
returns a copy of the QoreString that the caller owns
Definition: QoreStringNode.h:534
QoreStringNodeValueHelper::operator*
DLLLOCAL const QoreStringNode * operator*()
returns the object being managed
Definition: QoreStringNode.h:458
QoreNodeAsStringHelper::~QoreNodeAsStringHelper
DLLLOCAL ~QoreNodeAsStringHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
Definition: QoreStringNode.h:513
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:417
QoreStringNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality (&quot;deep compare&quot; including all contained values for container types) without type o...
QoreStringNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object, the caller owns the reference count
QoreStringNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreStringNode.h:256
QoreString::operator=
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:33