QoreStringNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreStringNode.h
QoreStringNode Class Definition
Qore Programming Language
Copyright (C) 2003 - 2021 Qore Technologies, s.r.o.
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 <cstring>
class QoreStringNode : public SimpleValueQoreNode, public QoreString {
private:
QoreStringNode(QoreString* str) = delete;
QoreStringNode& operator=(const QoreStringNode&) = delete;
// note implemented; declared private here to probit them from being called
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, size_t maxlinelen);
DLLEXPORT QoreStringNode(char* nbuf, size_t nlen, size_t nallocated, const QoreEncoding* enc);
DLLEXPORT QoreStringNode(const char* str, 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;
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, QoreValue strn, ExceptionSink* xsink);
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 int parseInit(QoreValue& val, QoreParseContext& parse_context);
DLLLOCAL QoreStringNode(const char* str, const QoreEncoding* from, const QoreEncoding* to, ExceptionSink* xsink);
DLLLOCAL QoreStringNode(struct qore_string_private* p);
};
class QoreStringNodeMaker : public QoreStringNode {
public:
DLLEXPORT QoreStringNodeMaker(const char* fmt, ...);
private:
QoreStringNodeMaker(const QoreStringNodeMaker& str) = delete;
QoreStringNodeMaker& operator=(const QoreStringNodeMaker&) = delete;
};
extern QoreStringNode* NullString;
class QoreStringValueHelper {
public:
DLLEXPORT QoreStringValueHelper(const QoreValue n);
DLLEXPORT QoreStringValueHelper(const QoreValue n, const QoreEncoding* enc, ExceptionSink* xsink);
DLLEXPORT ~QoreStringValueHelper();
DLLEXPORT const QoreString* operator->();
DLLEXPORT const QoreString* operator*();
DLLEXPORT QoreString* giveString();
DLLEXPORT char* giveBuffer();
DLLEXPORT bool is_temp() const;
private:
QoreString* str;
bool del;
QoreStringValueHelper(const QoreStringValueHelper&) = delete;
QoreStringValueHelper& operator=(const QoreStringValueHelper&) = delete;
void* operator new(size_t) = delete;
DLLEXPORT void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = nullptr);
};
class QoreStringNodeValueHelper {
public:
DLLEXPORT QoreStringNodeValueHelper(const QoreValue n);
DLLEXPORT QoreStringNodeValueHelper(const QoreValue n, const QoreEncoding* enc, ExceptionSink* xsink);
DLLEXPORT ~QoreStringNodeValueHelper();
DLLEXPORT const QoreStringNode* operator->();
DLLEXPORT const QoreStringNode* operator*();
DLLEXPORT QoreStringNode* getReferencedValue();
DLLEXPORT bool is_temp() const;
private:
QoreStringNode* str;
bool del;
QoreStringNodeValueHelper(const QoreStringNodeValueHelper&) = delete;
QoreStringNodeValueHelper& operator=(const QoreStringNodeValueHelper&) = delete;
void* operator new(size_t) = delete;
DLLEXPORT void setup(ExceptionSink* xsink, const QoreValue n, const QoreEncoding* enc = nullptr);
};
#include <qore/ReferenceHolder.h>
typedef SimpleRefHolder<QoreStringNode> QoreStringNodeHolder;
extern QoreString NothingTypeString;
class QoreNodeAsStringHelper {
public:
DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode* n, int format_offset, ExceptionSink* xsink);
DLLEXPORT QoreNodeAsStringHelper(const QoreValue n, int format_offset, ExceptionSink* xsink);
DLLEXPORT ~QoreNodeAsStringHelper();
DLLEXPORT const QoreString* operator->();
DLLEXPORT const QoreString* operator*();
DLLEXPORT QoreString* giveString();
private:
QoreString* str;
bool del;
QoreNodeAsStringHelper(const QoreNodeAsStringHelper&) = delete;
QoreNodeAsStringHelper& operator=(const QoreNodeAsStringHelper&) = delete;
void* operator new(size_t) = delete;
};
#endif
QoreStringNode::getAsString
DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const
concatenates the string data in double quotes to an existing QoreString
QoreStringNode::~QoreStringNode
virtual DLLEXPORT ~QoreStringNode()
destructor only called when references = 0, use deref() instead
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
QoreStringNodeValueHelper::operator->
DLLEXPORT const QoreStringNode * operator->()
returns the object being managed
QoreStringNode::reverse
DLLEXPORT QoreStringNode * reverse() const
return a QoreStringNode with the characters reversed
QoreStringValueHelper::giveBuffer
DLLEXPORT char * giveBuffer()
returns a char* string that the caller owns and must free()
QoreStringNode::stringRefSelf
DLLEXPORT QoreStringNode * stringRefSelf() const
references the object and returns a non-const pointer to "this"
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
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
QoreStringNodeValueHelper::operator*
DLLEXPORT const QoreStringNode * operator*()
returns the object being managed
QoreStringNodeValueHelper::is_temp
DLLEXPORT bool is_temp() const
returns true if the reference being managed is temporary
QoreNodeAsStringHelper
safely manages the return values to AbstractQoreNode::getAsString(), stack only, cannot be dynamicall...
Definition: QoreStringNode.h:442
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
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
QoreStringValueHelper::operator->
DLLEXPORT const QoreString * operator->()
returns the object being managed
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
QoreStringNodeValueHelper::getReferencedValue
DLLEXPORT QoreStringNode * getReferencedValue()
returns a referenced value - the caller will own the reference
QoreNodeAsStringHelper::operator*
DLLEXPORT const QoreString * operator*()
returns the object being managed
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
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...
QoreStringValueHelper::QoreStringValueHelper
DLLEXPORT QoreStringValueHelper(const QoreValue n)
creates the object and acquires a pointer to the QoreString representation of the QoreValue passed ...
QoreStringNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreStringValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:297
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode()
creates an empty string and assigns the default encoding QCS_DEFAULT
QoreNodeAsStringHelper::QoreNodeAsStringHelper
DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode *n, int format_offset, ExceptionSink *xsink)
makes the call to AbstractQoreNode::getAsString() and manages the return values
QoreString::length
DLLEXPORT size_t length() const
returns the number of characters (not bytes) in the 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...
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
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 "offset" and returns a string of the characte...
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
SimpleRefHolder
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
QoreStringNode::is_equal_hard
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...
QoreStringNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the current string and sets del to false
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:260
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
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:366
QoreStringNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreStringNode.h:263
QoreStringValueHelper::giveString
DLLEXPORT QoreString * giveString()
returns a copy of the QoreString that the caller owns
QoreStringValueHelper::operator*
DLLEXPORT const QoreString * operator*()
returns the object being managed
QoreNodeAsStringHelper::operator->
DLLEXPORT const QoreString * operator->()
returns the object being managed
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:70
QoreStringNode::parseInit
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:372
QoreStringValueHelper::~QoreStringValueHelper
DLLEXPORT ~QoreStringValueHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer ...
QoreStringNode::is_equal_soft
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 ...
QoreStringNode::getDateTimeRepresentation
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this string
QoreStringNode::parseBase64ToString
DLLEXPORT QoreStringNode * parseBase64ToString(ExceptionSink *xsink) const
parses the string as a base64-encoded binary and returns the decoded value as a QoreStringNode ...
QoreStringValueHelper::is_temp
DLLEXPORT bool is_temp() const
returns true if the pointer being managed is temporary
QoreStringNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreStringNode.h:258
QoreStringNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object, the caller owns the reference count
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