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 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QORESTRINGNODE_H
#define _QORE_QORESTRINGNODE_H
#include <qore/AbstractQoreNode.h>
#include <qore/QoreString.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;
}
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 {
private:
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
public:
DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n) {
if (n) {
//optimization to remove the need for a virtual function call in the most common case
if (n->getType() == NT_STRING) {
del = false;
str = const_cast< QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
}
else
str = n->getStringRepresentation(del);
}
else {
str = NullString;
del = false;
}
}
DLLLOCAL QoreStringValueHelper(const AbstractQoreNode *n, const QoreEncoding *enc, ExceptionSink *xsink) {
if (n) {
//optimization to remove the need for a virtual function call in the most common case
if (n->getType() == NT_STRING) {
del = false;
str = const_cast< QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
}
else
str = n->getStringRepresentation(del);
if (str->getEncoding() != enc) {
QoreString *t = str->convertEncoding(enc, xsink);
if (!t)
return;
if (del)
delete str;
str = t;
del = true;
}
}
else {
str = NullString;
del = false;
}
}
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 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:
DLLLOCAL QoreStringNodeValueHelper(const AbstractQoreNode *n) {
if (!n) {
str = NullString;
temp = false;
return;
}
qore_type_t ntype = n->getType();
if (ntype == NT_STRING) {
str = const_cast< QoreStringNode *>(reinterpret_cast<const QoreStringNode *>(n));
temp = false;
}
else {
str = new QoreStringNode();
n->getStringRepresentation(*(static_cast<QoreString *>(str)));
temp = true;
}
}
DLLLOCAL ~QoreStringNodeValueHelper() {
if (temp)
str->deref();
}
DLLLOCAL const QoreStringNode *operator->() { return str; }
DLLLOCAL const QoreStringNode *operator*() { return str; }
DLLLOCAL QoreStringNode *getReferencedValue() {
if (temp)
temp = false;
else if (str)
str->ref();
return str;
}
};
#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);
DLLLOCAL ~QoreNodeAsStringHelper() {
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;
}
};
#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:62
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:65
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:59
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