Loading...
Searching...
No Matches
QoreStringNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreStringNode.h
QoreStringNode Class Definition
Qore Programming Language
Copyright (C) 2003 - 2022 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;
DLLEXPORT QoreStringNode* regexSubst(QoreString& match, QoreString& subst, int opts, ExceptionSink* xsink) 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
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
QoreNodeAsStringHelper
safely manages the return values to AbstractQoreNode::getAsString(), stack only, cannot be dynamicall...
Definition: QoreStringNode.h:454
QoreNodeAsStringHelper::QoreNodeAsStringHelper
DLLEXPORT QoreNodeAsStringHelper(const AbstractQoreNode *n, int format_offset, ExceptionSink *xsink)
makes the call to AbstractQoreNode::getAsString() and manages the return values
QoreNodeAsStringHelper::operator->
DLLEXPORT const QoreString * operator->()
returns the object being managed
QoreNodeAsStringHelper::operator*
DLLEXPORT const QoreString * operator*()
returns the object being managed
QoreNodeAsStringHelper::QoreNodeAsStringHelper
DLLEXPORT QoreNodeAsStringHelper(const QoreValue n, int format_offset, ExceptionSink *xsink)
makes the call to AbstractQoreNode::getAsString() and manages the return values
QoreNodeAsStringHelper::~QoreNodeAsStringHelper
DLLEXPORT ~QoreNodeAsStringHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer
QoreNodeAsStringHelper::giveString
DLLEXPORT QoreString * giveString()
returns a copy of the QoreString that the caller owns
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
QoreString::length
DLLEXPORT size_t length() const
returns the number of characters (not bytes) in the string
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode(const char *str, size_t len, const QoreEncoding *new_qorecharset=QCS_DEFAULT)
copies the c-string passed (up to len) and assigns the encoding passed
QoreStringNode::regexSubst
DLLEXPORT QoreStringNode * regexSubst(QoreString &match, QoreString &subst, int opts, ExceptionSink *xsink) const
performs perl5-compatible regular expression substitution
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
DLLEXPORT QoreStringNode(const std::string &str, const QoreEncoding *enc=QCS_DEFAULT)
creates a new object from a std::string and sets the character encoding
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...
QoreStringNode::QoreStringNode
DLLLOCAL QoreStringNode(struct qore_string_private *p)
constructor using the private implementation of QoreString; not exported in the library
QoreStringNode::QoreStringNode
DLLLOCAL QoreStringNode(const char *str, const QoreEncoding *from, const QoreEncoding *to, ExceptionSink *xsink)
constructor supporting createAndConvertEncoding(), not exported in the library
QoreStringNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
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
QoreStringNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the current string and sets del to false
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode(const BinaryNode *bin, size_t maxlinelen)
creates a new string as the base64-encoded value of the binary object passed and ensures the maximum ...
QoreStringNode::parseInit
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
QoreStringNode::parseBase64ToString
DLLEXPORT QoreStringNode * parseBase64ToString(const QoreEncoding *enc, ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a QoreStringNode pointer owne...
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::extract
DLLEXPORT QoreStringNode * extract(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink)
removes "length" characters from the string starting at position "offset" and returns a string of the...
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,...
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode(const char *str, const QoreEncoding *enc=QCS_DEFAULT)
creates a new object from a string and sets the character encoding
QoreStringNode::stringRefSelf
DLLEXPORT QoreStringNode * stringRefSelf() const
references the object and returns a non-const pointer to "this"
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode()
creates an empty string and assigns the default encoding QCS_DEFAULT
QoreStringNode::extract
DLLEXPORT QoreStringNode * extract(qore_offset_t offset, qore_offset_t length, QoreValue strn, ExceptionSink *xsink)
removes "length" characters from the string starting at position "offset" and replaces them with the ...
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...
QoreStringNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreStringNode.h:275
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode(const QoreString &str)
creates a new QoreStringNode from an existing QoreString reference
QoreStringNode::getStringRepresentation
virtual DLLEXPORT void getStringRepresentation(QoreString &str) const
concatentates the value of the type to an existing QoreString reference
QoreStringNode::substr
DLLEXPORT QoreStringNode * substr(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink) const
returns a new string consisting of "length" characters from the current string starting with characte...
QoreStringNode::reverse
DLLEXPORT QoreStringNode * reverse() const
return a QoreStringNode with the characters reversed
QoreStringNode::getDateTimeRepresentation
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this string
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::QoreStringNode
DLLEXPORT QoreStringNode(const QoreStringNode &str)
creates a new QoreStringNode from an existing QoreStringNode reference
QoreStringNode::QoreStringNode
DLLEXPORT QoreStringNode(char *nbuf, size_t nlen, size_t nallocated, const QoreEncoding *enc)
creates a new object; takes ownership of the char pointer passed, all parameters are mandatory
QoreStringNode::~QoreStringNode
virtual DLLEXPORT ~QoreStringNode()
destructor only called when references = 0, use deref() instead
QoreStringNode::getAsString
DLLEXPORT QoreString * getAsString(bool &del, int format_offset, ExceptionSink *xsink) const
returns a QoreString giving the string data in double quotes
QoreStringNode::getDateTimeRepresentation
virtual DLLEXPORT void getDateTimeRepresentation(DateTime &dt) const
assigns the date representation of this string to the DateTime reference passed
QoreStringNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreStringNode.h:270
QoreStringNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object, the caller owns the reference count
QoreStringNode::parseBase64ToString
DLLEXPORT QoreStringNode * parseBase64ToString(ExceptionSink *xsink) const
parses the string as a base64-encoded binary and returns the decoded value as a QoreStringNode
QoreStringNodeValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a QoreS...
Definition: QoreStringNode.h:378
QoreStringNodeValueHelper::is_temp
DLLEXPORT bool is_temp() const
returns true if the reference being managed is temporary
QoreStringNodeValueHelper::getReferencedValue
DLLEXPORT QoreStringNode * getReferencedValue()
returns a referenced value - the caller will own the reference
QoreStringNodeValueHelper::~QoreStringNodeValueHelper
DLLEXPORT ~QoreStringNodeValueHelper()
destroys the object and dereferences the QoreStringNode if it is a temporary pointer
QoreStringNodeValueHelper::operator->
DLLEXPORT const QoreStringNode * operator->()
returns the object being managed
QoreStringNodeValueHelper::QoreStringNodeValueHelper
DLLEXPORT QoreStringNodeValueHelper(const QoreValue n, const QoreEncoding *enc, ExceptionSink *xsink)
gets the QoreString representation and ensures that it's in the desired encoding
QoreStringNodeValueHelper::operator*
DLLEXPORT const QoreStringNode * operator*()
returns the object being managed
QoreStringValueHelper
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:309
QoreStringValueHelper::operator->
DLLEXPORT const QoreString * operator->()
returns the object being managed
QoreStringValueHelper::~QoreStringValueHelper
DLLEXPORT ~QoreStringValueHelper()
destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer
QoreStringValueHelper::QoreStringValueHelper
DLLEXPORT QoreStringValueHelper(const QoreValue n, const QoreEncoding *enc, ExceptionSink *xsink)
gets the QoreString representation and ensures that it's in the desired encoding
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
QoreStringValueHelper::QoreStringValueHelper
DLLEXPORT QoreStringValueHelper(const QoreValue n)
creates the object and acquires a pointer to the QoreString representation of the QoreValue passed
QoreStringValueHelper::giveBuffer
DLLEXPORT char * giveBuffer()
returns a char* string that the caller owns and must free()
QoreStringValueHelper::is_temp
DLLEXPORT bool is_temp() const
returns true if the pointer being managed is temporary
SimpleRefHolder
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:372
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
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
NT_STRING
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:45
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276