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;
120 NBStorageManager nbs;
122 void DoStorage(
const char *cp,
int len);
124 static bool testInterpolationModifier(
const char *begin,
const char *end);
125 void modifyInterpValue(
char *bufStart,
char *valStart,
const char *valEnd,
const char *modStart,
const char *modEnd);
182 char &operator[](
size_t pos);
183 const char &operator[](
size_t pos)
const;
256 size_t find(
const char *str,
size_t pos = 0)
const;
268 size_t find(
const char *s,
size_t pos,
size_t n)
const;
279 size_t find(
char c,
size_t pos = 0)
const;
292 size_t replace(
const char *findStr,
char rep,
size_t startPos = 0,
size_t end = 0);
305 size_t replace(
char c,
char rep,
size_t startPos = 0,
size_t end = 0);
379 NBString &operator+=(
const char *str);
400 friend void NBStringBuilder::moveTo(
NBString &);
410 friend bool operator==(
const char *lhs,
const NBString &rhs);
411 friend bool operator==(
const NBString &lhs,
const char *rhs);
413 friend bool operator!=(
const char *lhs,
const NBString &rhs);
414 friend bool operator!=(
const NBString &lhs,
const char *rhs);
416 friend bool operator<(
const char *lhs,
const NBString &rhs);
417 friend bool operator<(
const NBString &lhs,
const char *rhs);
419 friend bool operator<=(
const char *lhs,
const NBString &rhs);
420 friend bool operator<=(
const NBString &lhs,
const char *rhs);
422 friend bool operator>(
const char *lhs,
const NBString &rhs);
423 friend bool operator>(
const NBString &lhs,
const char *rhs);
425 friend bool operator>=(
const char *lhs,
const NBString &rhs);
426 friend bool operator>=(
const NBString &lhs,
const char *rhs);
486 unsigned int stouihex()
const;
494 unsigned long stoulhex()
const;
515 friend NBString b64UrlToString(
const puint8_t p,
int len);
536 size_t copy(
char *s,
size_t len,
size_t pos = 0)
const;
547 size_t strcopy(
char *s,
size_t len,
size_t pos = 0)
const;
561NBString b64UrlToString(
const puint8_t p,
int len);
565class NBInterpolatedString :
public NBString
567 bool bNeedInterpolate;
573 NBInterpolatedString();
580 NBInterpolatedString(
const NBString &str);
589 NBInterpolatedString(
const NBString &str,
size_t pos,
size_t len = npos);
596 NBInterpolatedString(
const char *s);
604 NBInterpolatedString(
const char *s,
size_t n);
609 ~NBInterpolatedString();
612 NBInterpolatedString &operator=(
const NBString &str);
613 NBInterpolatedString &operator=(
const char *s);
625 NBString &Append(
const char *str,
size_t len);
637 NBString &FdAppend(
int fd,
size_t len);
640 NBString &operator+=(
const char *str);
643 NBInterpolatedString &Interpolate();
664inline bool operator==(
const char *lhs,
const NBString &rhs)
668inline bool operator==(
const NBString &lhs,
const char *rhs)
676inline bool operator!=(
const char *lhs,
const NBString &rhs)
680inline bool operator!=(
const NBString &lhs,
const char *rhs)
688inline bool operator<(
const char *lhs,
const NBString &rhs)
692inline bool operator<(
const NBString &lhs,
const char *rhs)
700inline bool operator<=(
const char *lhs,
const NBString &rhs)
704inline bool operator<=(
const NBString &lhs,
const char *rhs)
712inline bool operator>(
const char *lhs,
const NBString &rhs)
716inline bool operator>(
const NBString &lhs,
const char *rhs)
724inline bool operator>=(
const char *lhs,
const NBString &rhs)
728inline 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:112
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 *.
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.
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.
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:530
NetBurner System Functions.