34 #ifndef _QORE_QORESTRING_H 36 #define _QORE_QORESTRING_H 49 #define CE_HTML (1 << 0) 51 #define CE_XML (1 << 1) 53 #define CE_NONASCII (1 << 2) 55 #define CE_XHTML (CE_HTML | CE_XML) 57 #define CE_ALL (CE_XHTML | CE_NONASCII) 65 #define CD_HTML (1 << 0) 67 #define CD_XML (1 << 1) 69 #define CD_NUM_REF (1 << 2) 71 #define CD_XHTML (CD_HTML | CD_XML) 73 #define CD_ALL (CD_XHTML | CD_NUM_REF) 83 friend struct qore_string_private;
86 struct qore_string_private*
priv;
100 DLLLOCAL
void concat_reverse(
QoreString* targ)
const;
102 DLLLOCAL
int snprintf(
size_t size,
const char* fmt, ...);
103 DLLLOCAL
int vsnprintf(
size_t size,
const char* fmt, va_list args);
178 DLLEXPORT
void set(
char* nbuf,
size_t nlen,
size_t nallocated,
const QoreEncoding* enc);
268 DLLEXPORT
void concatEscape(
const char* str,
char c,
char esc_char =
'\\');
372 DLLEXPORT
void concat(
const char* str);
375 DLLEXPORT
void concat(
const std::string& str);
381 DLLEXPORT
void concat(
const char c);
403 DLLEXPORT
int compare(
const char* str)
const;
413 DLLEXPORT
bool equal(
const char* str)
const;
463 DLLEXPORT
int sprintf(
const char* fmt, ...);
468 DLLEXPORT
int vsprintf(
const char* fmt, va_list args);
473 DLLEXPORT
void take(
char* str);
505 DLLEXPORT
void clear();
510 DLLEXPORT
void reset();
515 DLLEXPORT
void replaceAll(
const char* old_str,
const char* new_str);
629 DLLEXPORT
void tolwr();
634 DLLEXPORT
void toupr();
649 DLLEXPORT
const char*
c_str()
const;
654 DLLEXPORT
void allocate(
unsigned requested_size);
674 DLLEXPORT
void addch(
char c,
unsigned times);
718 DLLEXPORT
void trim(
const char* chars = 0);
743 DLLEXPORT
void trim(
char c);
799 DLLEXPORT
void prepend(
const char* str);
817 DLLEXPORT
bool operator==(
const std::string& other)
const;
820 DLLEXPORT
bool operator==(
const char* other)
const;
824 return !(*
this == other);
829 return !(*
this == other);
834 return !(*
this == other);
852 DLLEXPORT
bool empty()
const;
921 DLLLOCAL
QoreString(
struct qore_string_private* p);
929 DLLLOCAL QoreStringMaker(
const QoreStringMaker& str);
932 DLLLOCAL QoreStringMaker&
operator=(
const QoreStringMaker&);
938 DLLEXPORT QoreStringMaker(
const char* fmt, ...);
943 DLLEXPORT QoreStringMaker(
const QoreEncoding* enc,
const char* fmt, ...);
967 void*
operator new(size_t);
995 DLLLOCAL
operator bool()
const {
return str != 0; }
1023 DLLLOCAL TempEncodingHelper&
operator=(
const TempEncodingHelper& );
1026 DLLLOCAL
void*
operator new(size_t);
1029 DLLLOCAL
void discard_intern() {
1059 set_intern(&s, qe, xsink);
1069 set_intern(s, qe, xsink);
1073 DLLLOCAL TempEncodingHelper() : str(0), temp(false) {
1077 DLLLOCAL ~TempEncodingHelper() {
1094 set_intern(s, qe, xsink);
1099 DLLLOCAL
bool is_temp()
const {
1104 DLLLOCAL
void makeTemp() {
1121 DLLLOCAL
operator bool()
const {
return str != 0; }
1138 DLLEXPORT
void removeBom();
DLLEXPORT const char * c_str() const
returns the string's buffer; this data should not be changed
DLLEXPORT void trim_trailing(const char *chars=0)
remove trailing whitespace or other characters
DLLEXPORT char operator[](qore_offset_t pos) const
returns the byte (not character) at the given location; if the location is invalid, returns 0
DLLEXPORT qore_offset_t bindex(const QoreString &needle, qore_offset_t pos) const
returns the byte position of a substring within the string or -1 if not found
DLLEXPORT QoreString()
creates an empty string and assigns the default encoding QCS_DEFAULT
DLLEXPORT BinaryNode * parseBase64(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a BinaryNode pointer (caller ...
DLLEXPORT void setEncoding(const QoreEncoding *new_encoding)
changes the tagged encoding to the given encoding; does not affect the actual string buffer...
struct qore_string_private * priv
the private implementation of QoreString
Definition: QoreString.h:86
defines string encoding functions in Qore
Definition: QoreEncoding.h:85
DLLEXPORT BinaryNode * parseHex(ExceptionSink *xsink) const
parses the current string data as hexadecimal-encoded data and returns it as a BinaryNode pointer (ca...
DLLEXPORT QoreString * parseBase64ToString(ExceptionSink *xsink) const
parses the current string data as base64-encoded data and returns it as a QoreString pointer owned by...
DLLEXPORT bool empty() const
returns true if the string is empty, false if not
DLLEXPORT void concatDecodeUrl(const char *url)
concatenates a URL-decoded version of the c-string passed
DLLEXPORT void replaceAll(const char *old_str, const char *new_str)
replaces all occurences of the first string with the second string
DLLEXPORT qore_offset_t rindex(const QoreString &needle, qore_offset_t pos, ExceptionSink *xsink) const
returns the character position of a substring searching in reverse from a given position or -1 if not...
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
DLLEXPORT void concatEscape(const QoreString *str, char c, char esc_char, ExceptionSink *xsink)
concatenates a string and escapes character c with esc_char (converts encodings if necessary) ...
DLLEXPORT bool equalSoft(const QoreString &str, ExceptionSink *xsink) const
returns true if the strings are equal, false if not, if the character encodings are different...
DLLEXPORT unsigned int getUnicodePointFromBytePos(qore_size_t offset, unsigned &len, ExceptionSink *xsink) const
return Unicode code point for the given byte offset
DLLEXPORT void trim_single_trailing(char c)
remove a single trailing character if present
DLLEXPORT qore_offset_t rfindAny(const char *str, qore_offset_t pos=-1) const
returns the last byte position of any of the given characters (bytes) within the string or -1 if not ...
DLLEXPORT void reserve(qore_size_t size)
ensures that at least the given size is available in the string; the string's contents are not affect...
DLLEXPORT void concatHex(const char *buf, qore_size_t size)
concatenates hexidecimal digits corresponding to the binary data passed up to byte "len" ...
DLLEXPORT qore_offset_t find(char c, qore_offset_t pos=0) const
returns the byte position of a character (byte) within the string or -1 if not found ...
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...
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
DLLEXPORT char * giveBuffer()
returns the character buffer and leaves the QoreString empty, the caller owns the memory returned (mu...
DLLEXPORT qore_offset_t getByteOffset(qore_size_t i, ExceptionSink *xsink) const
returns the byte position of the given character position in the string or -1 if the string does not ...
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
DLLEXPORT qore_offset_t index(const QoreString &needle, qore_offset_t pos, ExceptionSink *xsink) const
returns the character position of a substring within the string or -1 if not found ...
DLLEXPORT void concatISO8601DateTime(const DateTime *d)
concatenates a DateTime value to a string in the format YYYYMMDDTHH:mm:SS <- where the "T" is a liter...
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:74
DLLEXPORT void tolwr()
converts the string to lower-case in place
DLLEXPORT void prepend(const char *str)
prepends the string given to the string, assumes character encoding is the same as the string's ...
DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset"
DLLEXPORT void concatUTF8FromUnicode(unsigned code)
append a UTF-8 character sequence from a unicode code point, assumes the string is tagged with QCS_UT...
DLLEXPORT int concatDecodeUriRequest(const QoreString &url, ExceptionSink *xsink)
concatenates a URI-decoded version of the c-string passed
DLLEXPORT bool isDataAscii() const
returns true if the string is empty or has no characters with the high bit set (ie all characters < 1...
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
DLLEXPORT void replace(qore_size_t offset, qore_size_t len, const char *str)
replaces bytes with the string passed
DLLEXPORT QoreString * copy() const
returns an exact copy of the string
DLLEXPORT QoreString * substr(qore_offset_t offset, ExceptionSink *xsink) const
returns a new string consisting of all the characters from the current string starting with character...
#define CE_XHTML
code for encoding XHTML entities
Definition: QoreString.h:56
DLLEXPORT const char * getBuffer() const
returns the string's buffer; this data should not be changed
class used to hold a possibly temporary QoreString pointer, stack only, cannot be dynamically allocat...
Definition: QoreString.h:956
DLLEXPORT int insertch(char c, qore_size_t pos, unsigned times)
insert a character at a certain position in the string a number of times
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
DLLEXPORT void toupr()
converts the string to upper-case in place
DLLEXPORT unsigned int getUnicodePointFromUTF8(qore_offset_t offset=0) const
return Unicode code point for character offset, string must be UTF-8
DLLEXPORT bool operator==(const QoreString &other) const
returns true if the other string is equal to this string (encodings also must be equal) ...
DLLEXPORT void concatBase64(const char *buf, qore_size_t size)
concatenates the base64-encoded version of the binary data passed
DLLEXPORT qore_size_t strlen() const
returns number of bytes in the string (not including the null pointer)
DLLEXPORT bool equalPartialPath(const QoreString &str, ExceptionSink *xsink) const
returns true if the begining of the current string matches the argument string where either both stri...
DLLEXPORT bool equalPartialSoft(const QoreString &str, ExceptionSink *xsink) const
returns true if the beginning of the current string matches the argument string, false if not...
#define CD_ALL
code for decoding everything
Definition: QoreString.h:74
use this class to manage strings where the character encoding must be specified and may be different ...
Definition: QoreString.h:1014
DLLEXPORT qore_offset_t findAny(const char *str, qore_offset_t pos=0) const
returns the byte position of any of the given characters (bytes) within the string or -1 if not found...
DLLLOCAL bool operator!=(const QoreString &other) const
returns true if the other string is not equal to this string (encodings also must be equal) ...
Definition: QoreString.h:823
DLLEXPORT unsigned int getUnicodePoint(qore_offset_t offset, ExceptionSink *xsink) const
return Unicode code point for the single character at the given character (not byte) offset in the st...
DLLEXPORT int concatDecode(ExceptionSink *xsink, const QoreString &str, unsigned code=CD_ALL)
concatenates a string and decodes HTML, XML, and numeric character references as per the supplied arg...
DLLEXPORT int insert(const char *str, qore_size_t pos)
inserts a character string at a certain position in the string
DLLEXPORT void concatAndHTMLEncode(const char *str)
concatenates HTML-encoded version of the c-string passed
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
DLLEXPORT bool equalPartial(const QoreString &str) const
returns true if the beginning of the current string matches the argument string, false if not...
DLLEXPORT int concatEncode(ExceptionSink *xsink, const QoreString &str, unsigned code=CE_XHTML)
concatenates a string and encodes it according to the encoding argument passed
DLLEXPORT int concatEncodeUrl(ExceptionSink *xsink, const QoreString &url, bool encode_all=false)
concatenates a URL-encoded version of the c-string passed
DLLEXPORT void trim_leading(const char *chars=0)
remove leading whitespace or other characters
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:241
DLLEXPORT void replaceChar(qore_size_t offset, char c)
replaces a byte with the byte passed
DLLEXPORT void addch(char c, unsigned times)
append a character to the string a number of times
DLLEXPORT qore_size_t capacity() const
returns number of bytes allocated for the string's buffer, capacity is always >= size ...
DLLEXPORT void terminate(qore_size_t size)
terminates the string at byte position "size", the string is reallocated if necessary ...
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:77
DLLEXPORT void trim(const char *chars=0)
remove leading and trailing whitespace or other characters
DLLEXPORT qore_offset_t rfind(char c, qore_offset_t pos=-1) const
returns the last byte position of a character (byte) within the string or -1 if not found ...
DLLEXPORT int trimTrailing(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes trailing whitespace or other characters
DLLEXPORT int concatUnicode(unsigned code, ExceptionSink *xsink)
append a character sequence from a unicode code point (returns 0 for OK, -1 for exception) ...
DLLEXPORT QoreString & operator+=(const char *str)
concatenates the characters to the string; assumes the string to be concatenated is already in the ch...
DLLEXPORT qore_size_t chomp()
removes a single \n\r or \n from the end of the string and returns the number of characters removed ...
DLLEXPORT bool equal(const QoreString &str) const
returns true if the strings are equal, false if not, if the character encodings are different...
DLLEXPORT ~QoreString()
frees any memory allocated by the string
DLLEXPORT void takeAndTerminate(char *str, qore_size_t size)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
DLLEXPORT QoreString * extract(qore_offset_t offset, ExceptionSink *xsink)
removes characters from the string starting at position "offset" and returns a string of the characte...
DLLEXPORT int64 toBigInt() const
returns the value of the string as an int64
DLLEXPORT void allocate(unsigned requested_size)
Ensure the internal buffer has at least expected size in bytes.
DLLEXPORT int trimLeading(ExceptionSink *xsink, const QoreString *chars=nullptr)
removes leading whitespace or other characters
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding for the string
DLLEXPORT bool isDataPrintableAscii() const
returns true if the string is empty or only contains printable non-control ASCII characters (ie all c...
DLLEXPORT int compareSoft(const QoreString *str, ExceptionSink *xsink) const
compares the string with another string, performing character set encoding conversion if necessary ...
DLLEXPORT void reset()
reset string to zero length; memory is deallocated; string encoding is reset to QCS_DEFAULT ...
DLLEXPORT void clear()
reset string to zero length; memory is not deallocated; string encoding does not change ...
DLLEXPORT qore_offset_t brindex(const QoreString &needle, qore_offset_t pos) const
returns the byte position of a substring within the string searching in reverse from a given position...
DLLEXPORT void concatAndHTMLDecode(const QoreString *str)
concatenates HTML-decoded version of the c-string passed
DLLEXPORT void trim_single_leading(char c)
remove a single leading character if present
DLLEXPORT qore_size_t size() const
returns number of bytes in the string (not including the null pointer)
DLLEXPORT int vsprintf(const char *fmt, va_list args)
this will concatentate a formatted string to the existing string according to the format string and t...
DLLEXPORT int compare(const QoreString *str) const
compares two strings without converting encodings (if the encodings do not match then "this" is deeme...
DLLEXPORT void take(char *str)
takes ownership of the character pointer passed and assigns it to the string (frees memory previously...
DLLEXPORT QoreString & operator=(const QoreString &other)
assigns the value of one string to another
DLLEXPORT int concatEncodeUriRequest(ExceptionSink *xsink, const QoreString &url)
concatenates a URI-encoded version of the c-string passed
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT qore_size_t length() const
returns the number of characters (not bytes) in the string
DLLEXPORT QoreString * reverse() const
return a Qorestring with the characters reversed