22#define DEF_NB_STRING (1)
27#include <fd_adapter.h>
32const int native_string_storage = 15;
37const size_t npos = -1;
38const size_t NO_POS =-1;
40const uint8_t FLAG_LOCAL = 0x80;
41const uint8_t FLAG_CONST = 0x40;
42const uint8_t FLAG_ALLOC = 0x20;
43const uint8_t FLAG_CLEAR_LOCAL_MASK = 0x7F;
44const int EXTRA_ALLOC_SPACE = 64;
49struct nbstring_allocated_info
62 uint8_t stor[native_string_storage];
71 nbstring_allocated_info inf;
75 inline bool IsConstStore()
const {
return ((inf.flag & FLAG_CONST)!=0);};
76 inline bool IsLocalStore()
const {
return ((inf.flag & FLAG_LOCAL)!=0);};
78 void reservespace(
size_t n);
79 void setusedsize(
size_t n);
81 size_t GetUsed()
const;
82 size_t GetAvailable()
const;
84 const char *GetConstBuf()
const;
86 void SetFromConstant(
const char *c,
int len);
93 static void swap(NBStorageManager &n1, NBStorageManager &n2);
102class NBStringBuilder :
public NBStorageManager,
public fd_adapter
105 int read(
char *buf,
int nbytes)
override;
106 int write(
const char *buf,
int nbytes)
override;
107 int close()
override;
119 bool endswith(
const char *s,
size_t slen);
121 NBStorageManager nbs;
123 void DoStorage(
const char *cp,
int len);
125 static bool testInterpolationModifier(
const char *begin,
const char *end);
126 void modifyInterpValue(
char *bufStart,
char *valStart,
const char *valEnd,
const char *modStart,
const char *modEnd);
191 char &posRef(
size_t pos);
192 char &operator[](
size_t pos);
193 const char &operator[](
size_t pos)
const;
266 size_t find(
const char *str,
size_t pos = 0)
const;
278 size_t find(
const char *s,
size_t pos,
size_t n)
const;
289 size_t find(
char c,
size_t pos = 0)
const;
302 size_t replace(
const char *findStr,
char rep,
size_t startPos = 0,
size_t end = 0);
315 size_t replace(
char c,
char rep,
size_t startPos = 0,
size_t end = 0);
318 bool endswith(
const char *s);
396 NBString &operator+=(
const char *str);
417 friend void NBStringBuilder::moveTo(
NBString &);
427 friend bool operator==(
const char *lhs,
const NBString &rhs);
428 friend bool operator==(
const NBString &lhs,
const char *rhs);
430 friend bool operator!=(
const char *lhs,
const NBString &rhs);
431 friend bool operator!=(
const NBString &lhs,
const char *rhs);
433 friend bool operator<(
const char *lhs,
const NBString &rhs);
434 friend bool operator<(
const NBString &lhs,
const char *rhs);
436 friend bool operator<=(
const char *lhs,
const NBString &rhs);
437 friend bool operator<=(
const NBString &lhs,
const char *rhs);
439 friend bool operator>(
const char *lhs,
const NBString &rhs);
440 friend bool operator>(
const NBString &lhs,
const char *rhs);
442 friend bool operator>=(
const char *lhs,
const NBString &rhs);
443 friend bool operator>=(
const NBString &lhs,
const char *rhs);
503 unsigned int stouihex()
const;
511 unsigned long stoulhex()
const;
532 friend NBString b64UrlToString(
const puint8_t p,
int len);
553 size_t copy(
char *s,
size_t len,
size_t pos = 0)
const;
564 size_t strcopy(
char *s,
size_t len,
size_t pos = 0)
const;
598NBString b64UrlToString(
const puint8_t p,
int len);
656 bool bNeedInterpolate;
729 NBString &operator+=(
const char *str);
763inline bool operator==(
const char *lhs,
const NBString &rhs)
767inline bool operator==(
const NBString &lhs,
const char *rhs)
775inline bool operator!=(
const char *lhs,
const NBString &rhs)
779inline bool operator!=(
const NBString &lhs,
const char *rhs)
787inline bool operator<(
const char *lhs,
const NBString &rhs)
791inline bool operator<(
const NBString &lhs,
const char *rhs)
799inline bool operator<=(
const char *lhs,
const NBString &rhs)
803inline bool operator<=(
const NBString &lhs,
const char *rhs)
811inline bool operator>(
const char *lhs,
const NBString &rhs)
815inline bool operator>(
const NBString &lhs,
const char *rhs)
823inline bool operator>=(
const char *lhs,
const NBString &rhs)
827inline bool operator>=(
const NBString &lhs,
const char *rhs)
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Represents a positional reference (pointer) of a location inside a ParsedJsonDataSet object.
Definition json_lexer.h:113
A wrapper for NBString::Interpolate() ideal for easy access to ephemeral values.
Definition nbstring.h:655
NBString & Append(const char *str, size_t len)
Append a string to an existing NBString object.
~NBInterpolatedString()
NBInterpolatedString destructor.
NBInterpolatedString()
Construct a NBInterpolatedString object.
NBInterpolatedString & Interpolate()
Perform a string interpolation in-place. This allows NBStrings to easily access the NetBurner Config ...
NBInterpolatedString(const NBString &str)
Construct a new NBInterpolatedString object from an existing NBInterpolatedString object.
NBInterpolatedString(const char *s)
Construct a NBInterpolatedString object from a character string (null terminated array of characters)
NBInterpolatedString(const char *s, size_t n)
Construct a NBInterpolatedString object from a character string up to the specified amount.
NBInterpolatedString(const NBString &str, size_t pos, size_t len=npos)
Construct a new NBInterpolatedString object from a substring of an existing NBInterpolatedString obje...
NBString & FdAppend(int fd, size_t len)
Append from a file descriptor to an existing NBString object.
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
int compare(const NBString &str) const
Compares two NBString objects.
size_t find(const char *s, size_t pos, size_t n) const
Find a substring within a character string.
long stol() const
Parse the string value and convert to a long integer number.
~NBString()
NBString destructor.
NBString(const NBString &str)
Construct a new NBString object from an existing NBString object.
NBString(const char *s)
Construct a NBString object from a character string (null terminated array of characters)
size_t size() const
Returns the current size of memory allocated for the string.
const char * c_str() const
Method to pass a NBString as a constant char *.
bool Interpolate(NBString &dest)
Perform a string interpolation and place the finished interpolation in the Destination string....
size_t length() const
Returns the length of the string.
friend void swap(NBString &x, NBString &y)
Swaps the contents of two NBString objects.
IPADDR to_ipaddr() const
Parse the string value and convert to an IPADDR IP address.
unsigned long stoul() const
Parse the string value and convert to a const unsigned long integer number.
size_t find(const char *str, size_t pos=0) const
Find a substring within a character string.
void clear()
Clear a NBString object and free allocated memory.
size_t replace(const char *findStr, char rep, size_t startPos=0, size_t end=0)
Replace all occurrences of all "<findStr>" characters within the NBString object.
bool empty() const
Check if a string is empty.
int vsiprintf(const char *format, va_list &vl)
Print to a string with formatting.
int stoi() const
Parse the string and convert to an integer number.
unsigned int stoui() const
Parse the string value and convert to a const integer number.
int compare(const char *s) const
Compares the NBString object to a character string.
void shrink(int n)
Reduces the length of the string by n.
bool Interpolate()
Perform an in-place string interpolation. This allows NBStrings to easily access the NetBurner Config...
Definition nbstring.h:595
double stod() const
Parse the string value and convert to a const double float number.
NBString & FdAppend(int fd, size_t len)
Append from a file descriptor to an existing NBString object.
int siprintf(NBString const format,...)
isprintf (integer) to a string with formatting to a NBString object
NBString()
Construct a NBString object.
NBString substr(size_t pos=0, size_t len=npos) const
Creates a new NBString object from a substring of the existing NBString object.
NBString & Reserve(size_t len)
Reserve an additional buffer amount.
size_t copy(char *s, size_t len, size_t pos=0) const
Copy a substring, does not null terminate.
size_t find(const NBString str, size_t pos=0) const
Find a substring within a NBString object.
size_t find(char c, size_t pos=0) const
Find the first occurence of a character within the NBString object.
NBString(const JsonRef &jr)
Construct a NBString object using the current string referenced by a JsonRef. This allows for using L...
int sprintf(const char *format,...)
sprintf to a string with formatting to a character array
NBString & Append(const char *str, size_t len)
Append a string to an existing NBString object.
NBString(const char *s, size_t n)
Construct a NBString object from a character string up to the specified amount.
NBString(const NBString &str, size_t pos, size_t len=npos)
Construct a new NBString object from a substring of an existing NBString object.
size_t strcopy(char *s, size_t len, size_t pos=0) const
Copy a substring, with null termination.
int siprintf(const char *format,...)
isprintf (integer) to a string with formatting to a character array
int sprintf(NBString const format,...)
sprintf to a string with formatting as a NBString object
size_t replace(char c, char rep, size_t startPos=0, size_t end=0)
Replace all occurrences of all "<findStr>" characters within the NBString object.
A class to create, read, and modify a JSON object.
Definition json_lexer.h:535