All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreStringNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreStringNode.h
QoreStringNode Class Definition
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORESTRINGNODE_H
#define _QORE_QORESTRINGNODE_H
#include <qore/AbstractQoreNode.h>
#include <qore/QoreString.h>
#include <string.h>
class QoreStringNode : public SimpleValueQoreNode, public QoreString {
private:
DLLLOCAL QoreStringNode(QoreString* str);
DLLLOCAL QoreStringNode& operator=(const QoreStringNode&);
DLLLOCAL virtual bool getAsBoolImpl() const;
DLLLOCAL virtual int getAsIntImpl() const;
DLLLOCAL virtual int64 getAsBigIntImpl() const;
DLLLOCAL virtual double getAsFloatImpl() const;
protected:
DLLEXPORT virtual ~QoreStringNode();
public:
DLLEXPORT QoreStringNode();
DLLEXPORT QoreStringNode(const char* str, const QoreEncoding* enc = QCS_DEFAULT);
DLLEXPORT QoreStringNode(const QoreString& str);
DLLEXPORT QoreStringNode(const QoreStringNode& str);
DLLEXPORT QoreStringNode(const std::string& str, const QoreEncoding* enc = QCS_DEFAULT);
// copies binary object and makes a base64-encoded string out of it
DLLEXPORT QoreStringNode(const BinaryNode* b);
DLLEXPORT QoreStringNode(const BinaryNode* bin, qore_size_t maxlinelen);
DLLEXPORT QoreStringNode(char* nbuf, qore_size_t nlen, qore_size_t nallocated, const QoreEncoding* enc);
DLLEXPORT QoreStringNode(const char* str, qore_size_t len, const QoreEncoding* new_qorecharset = QCS_DEFAULT);
// creates a string from a single character
DLLEXPORT QoreStringNode(char c);
DLLEXPORT int getAsString(QoreString& str, int format_offset, ExceptionSink* xsink) const;
DLLEXPORT QoreString* getAsString(bool& del, int format_offset, ExceptionSink* xsink) const;
DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
DLLEXPORT virtual AbstractQoreNode* realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual const char* getTypeName() const;
DLLEXPORT QoreStringNode* convertEncoding(const QoreEncoding* nccs, ExceptionSink* xsink) const;
DLLEXPORT QoreStringNode* substr(qore_offset_t offset, ExceptionSink* xsink) const;
DLLEXPORT QoreStringNode* substr(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink) const;
DLLEXPORT QoreStringNode* reverse() const;
// copy function
DLLEXPORT QoreStringNode* copy() const;
DLLEXPORT static QoreStringNode* createAndConvertEncoding(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* parseBase64ToString(ExceptionSink* xsink) const;
DLLEXPORT QoreStringNode* parseBase64ToString(const QoreEncoding* enc, ExceptionSink* xsink) const;
DLLEXPORT QoreStringNode* stringRefSelf() const;
DLLLOCAL QoreStringNode(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* extract(qore_offset_t offset, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* extract(qore_offset_t offset, qore_offset_t length, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode* strn, ExceptionSink* xsink);
DLLLOCAL QoreStringNode(struct qore_string_private* p);
DLLLOCAL static const char* getStaticTypeName() {
return "string";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_STRING;
}
static const qore_type_t TYPE = NT_STRING;
DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
};
class QoreStringNodeMaker : public QoreStringNode {
private:
DLLLOCAL QoreStringNodeMaker(const QoreStringNodeMaker& str);
DLLLOCAL QoreStringNodeMaker& operator=(const QoreStringNodeMaker&);
public:
DLLEXPORT QoreStringNodeMaker(const char* fmt, ...);
};
extern QoreStringNode* NullString;
class QoreStringValueHelper {
protected:
QoreString* str;
bool del;
DLLLOCAL QoreStringValueHelper(const QoreStringValueHelper&); // not implemented
DLLLOCAL QoreStringValueHelper& operator=(const QoreStringValueHelper&); // not implemented
DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
DLLLOCAL void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = 0);
public:
DLLEXPORT QoreStringValueHelper(const AbstractQoreNode* n);
DLLEXPORT explicit QoreStringValueHelper(const QoreValue& n);
DLLEXPORT QoreStringValueHelper(const AbstractQoreNode* n, const QoreEncoding* enc, ExceptionSink* xsink);
DLLEXPORT QoreStringValueHelper(const QoreValue& n, const QoreEncoding* enc, ExceptionSink* xsink);
DLLLOCAL ~QoreStringValueHelper() {
if (del)
delete str;
}
DLLLOCAL const QoreString* operator->() { return str; }
DLLLOCAL const QoreString* operator*() { return str; }
DLLLOCAL QoreString* giveString() {
if (!str)
return 0;
if (!del)
return str->copy();
QoreString* rv = str;
del = false;
str = 0;
return rv;
}
DLLLOCAL char* giveBuffer() {
if (!str)
return 0;
if (!del)
return strdup(str->getBuffer());
char* rv = str->giveBuffer();
delete str;
del = false;
str = 0;
return rv;
}
DLLLOCAL bool is_temp() const {
return del;
}
};
class QoreStringNodeValueHelper {
private:
QoreStringNode* str;
bool temp;
DLLLOCAL QoreStringNodeValueHelper(const QoreStringNodeValueHelper&);
DLLLOCAL QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&);
DLLLOCAL void* operator new(size_t);
public:
DLLEXPORT QoreStringNodeValueHelper(const AbstractQoreNode* n);
DLLEXPORT QoreStringNodeValueHelper(const QoreValue& n);
DLLEXPORT ~QoreStringNodeValueHelper();
DLLLOCAL const QoreStringNode* operator->() { return str; }
DLLLOCAL const QoreStringNode* operator*() { return str; }
DLLEXPORT QoreStringNode* getReferencedValue();
};
#include <qore/ReferenceHolder.h>
typedef SimpleRefHolder<QoreStringNode> QoreStringNodeHolder;
extern QoreString NothingTypeString;
class QoreNodeAsStringHelper {
private:
QoreString* str;
bool del;
DLLLOCAL QoreNodeAsStringHelper(const QoreNodeAsStringHelper&); // not implemented
DLLLOCAL QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&); // not implemented
DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
public:
DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode* n, int format_offset, ExceptionSink* xsink);
DLLEXPORT QoreNodeAsStringHelper(const QoreValue n, int format_offset, ExceptionSink* xsink);
DLLEXPORT ~QoreNodeAsStringHelper();
DLLLOCAL const QoreString* operator->() { return str; }
DLLLOCAL const QoreString* operator*() { return str; }
DLLEXPORT QoreString* giveString();
};
#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:366
QoreStringNodeValueHelper::operator->
DLLLOCAL const QoreStringNode * operator->()
returns the object being managed
Definition: QoreStringNode.h:433
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:85
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:503
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:469
QoreStringNodeValueHelper::~QoreStringNodeValueHelper
DLLEXPORT ~QoreStringNodeValueHelper()
destroys the object and dereferences the QoreStringNode if it is a temporary pointer ...
QoreNodeAsStringHelper::giveString
DLLEXPORT QoreString * giveString()
returns a copy of the QoreString that the caller owns
QoreStringValueHelper::operator=
DLLLOCAL QoreStringValueHelper & operator=(const QoreStringValueHelper &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
QoreString::giveBuffer
DLLEXPORT char * giveBuffer()
returns the character buffer and leaves the QoreString empty, the caller owns the memory returned (mu...
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
QoreNodeAsStringHelper::operator->
DLLLOCAL const QoreString * operator->()
returns the object being managed
Definition: QoreStringNode.h:497
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:71
QoreStringNodeValueHelper::getReferencedValue
DLLEXPORT QoreStringNode * getReferencedValue()
returns a referenced value - the caller will own the reference
QoreStringValueHelper::operator*
DLLLOCAL const QoreString * operator*()
returns the object being managed
Definition: QoreStringNode.h:360
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:394
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
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::giveBuffer
DLLLOCAL char * giveBuffer()
returns a char* string that the caller owns and must free()
Definition: QoreStringNode.h:381
QoreStringValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:302
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
QoreStringValueHelper::setup
DLLLOCAL void setup(ExceptionSink *xsink, const QoreValue n, const QoreEncoding *enc=0)
sets up the object / common initialization
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:345
NT_STRING
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:45
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:354
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:43
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:111
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
int64
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
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:74
QoreNodeAsStringHelper::~QoreNodeAsStringHelper
DLLEXPORT ~QoreNodeAsStringHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
QoreStringNodeValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a QoreS...
Definition: QoreStringNode.h:407
QoreStringNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreStringNode.h:271
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
QoreStringNodeValueHelper::operator*
DLLLOCAL const QoreStringNode * operator*()
returns the object being managed
Definition: QoreStringNode.h:439
QoreStringValueHelper::QoreStringValueHelper
DLLLOCAL QoreStringValueHelper(const QoreStringValueHelper &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:435
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:266
QoreString::operator=
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
QoreString::getBuffer
DLLEXPORT const char * getBuffer() const
returns the string&#39;s buffer; this data should not be changed