UCommon
ucommon::memstring Class Reference

A string class that uses a cstring buffer that is fixed in memory. More...

#include <string.h>

Inheritance diagram for ucommon::memstring:
Collaboration diagram for ucommon::memstring:

Public Member Functions

 memstring (void *memory, size_t size)
 Create an instance of a memory string.
 
void operator= (const char *text)
 Assign null terminated text to our object.
 
void operator= (String &object)
 Assign the text of a string to our object.
 
 ~memstring ()
 Destroy memory string.
 
- Public Member Functions inherited from ucommon::String
int __isoc99_vscanf (const char *format, va_list args)
 Scan input items from a string object.
 
void add (char character)
 Append a single character to our string buffer.
 
void add (const char *text)
 Append null terminated text to our string buffer.
 
char at (int position) const
 Return character found at a specific position in the string.
 
const char * begin (void) const
 Get pointer to first character in string for iteration.
 
char * c_mem ()
 
const char * c_str (void) const
 Get character text buffer of string object.
 
size_t ccount (const char *list) const
 Count number of occurrences of characters in string.
 
void chop (const char *list)
 Chop trailing characters from the string.
 
void chop (size_t count=1)
 Chop trailing characters from text.
 
const char * chr (char character) const
 Find pointer in string where specified character appears.
 
void clear (size_t offset)
 Clear a field of a filled string with filler.
 
void clear (void)
 Clear string by setting to empty.
 
virtual int compare (const char *string) const
 Compare the values of two string.
 
String copy (size_t offset, size_t size) const
 Convenience method for substring extraction.
 
size_t count (void) const
 Count all characters in the string (strlen).
 
void cut (size_t offset, size_t size=0)
 Cut (remove) text from string.
 
char * data (void)
 Get memory text buffer of string object.
 
const char * end (void) const
 Get pointer to last character in string for iteration.
 
void erase (void)
 Erase string memory.
 
void fill (size_t size, char fill)
 
const char * find (const char *list, size_t offset=0) const
 Find a character in the string.
 
bool full (void) const
 Test if the string's allocated space is all used up.
 
String get (size_t offset, size_t size=0) const
 Get a new string object as a substring of the current object.
 
String left (size_t size) const
 Convenience method for left of string.
 
size_t len (void) const
 Get length of string.
 
void lower (void)
 Convert string to lower case.
 
size_t offset (const char *pointer) const
 Find offset of a pointer into our string buffer.
 
 operator bool () const
 Test if string has data.
 
 operator const char * () const
 Casting reference to raw text string.
 
bool operator! () const
 Test if string is empty.
 
bool operator!= (const char *text) const
 Compare our object with null terminated text.
 
Stringoperator% (const char *text)
 Parse text from a string in a scan expression.
 
Stringoperator% (double &value)
 Parse double value from a string.
 
Stringoperator% (long &value)
 Parse long integer value from a string.
 
Stringoperator% (short &value)
 Parse short integer value from a string.
 
Stringoperator% (unsigned long &value)
 Parse long integer value from a string.
 
Stringoperator% (unsigned short &value)
 Parse short integer value from a string.
 
Stringoperator& (const char *text)
 Concatenate null terminated text to our object.
 
Stringoperator&= (const char *text)
 
const char * operator() (int offset) const
 Reference a string in the object by relative offset.
 
String operator() (int offset, size_t size) const
 Get a new substring through object expression.
 
const char * operator* () const
 Reference raw text buffer by pointer operator.
 
bool operator*= (const char *substring)
 
bool operator*= (regex &expr)
 
Stringoperator*= (size_t number)
 Delete a specified number of characters from start of string.
 
const String operator+ (const char *text) const
 Concatenate null terminated text to our object.
 
Stringoperator++ (void)
 Delete first character from string.
 
Stringoperator+= (const char *text)
 Concatenate text to an existing string object.
 
Stringoperator+= (size_t number)
 Delete a specified number of characters from start of string.
 
Stringoperator-- (void)
 Delete last character from string.
 
Stringoperator-= (size_t number)
 Delete a specified number of characters from end of string.
 
bool operator< (const char *text) const
 Compare our object with null terminated text.
 
Stringoperator<< (char code)
 
Stringoperator<< (const char *text)
 
bool operator<= (const char *text) const
 Compare our object with null terminated text.
 
Stringoperator= (const char *text)
 Assign text to our existing buffer.
 
Stringoperator= (const String &object)
 Assign our string with the cstring of another object.
 
bool operator== (const char *text) const
 Compare our object with null terminated text.
 
bool operator> (const char *text) const
 Compare our object with null terminated text.
 
bool operator>= (const char *text) const
 Compare our object with null terminated text.
 
const char operator[] (int offset) const
 Reference a single character in string object by array offset.
 
Stringoperator^= (const char *text)
 Create new cow instance and assign value from null terminated text.
 
Stringoperator^= (const String &object)
 Create new cow instance and assign value from another string object.
 
Stringoperator| (const char *text)
 Concatenate null terminated text to our object.
 
Stringoperator|= (const char *text)
 Concatenate text to an existing string object.
 
void paste (size_t offset, const char *text, size_t size=0)
 Insert (paste) text into string.
 
size_t printf (const char *format,...)
 Print items into a string object.
 
const char * rchr (char character) const
 Find pointer in string where specified character last appears.
 
unsigned replace (const char *string, const char *text=NULL, unsigned flags=0)
 
unsigned replace (regex &expr, const char *text=NULL, unsigned flags=0)
 
const char * rfind (const char *list, size_t offset=npos) const
 Find last occurrence of character in the string.
 
String right (size_t offset) const
 Convenience method for right of string.
 
void rset (const char *text, char overflow, size_t offset, size_t size=0)
 Set a text field within our string object offset from the end of buffer.
 
const char * rskip (const char *list, size_t offset=npos) const
 Skip trailing characters in the string.
 
void rsplit (const char *pointer)
 Split the string by a pointer position.
 
void rsplit (size_t offset)
 Split the string at a specific offset.
 
int scanf (const char *format,...)
 Scan input items from a string object.
 
const char * search (const char *string, unsigned instance=0, unsigned flags=0) const
 Search for a substring in the string.
 
const char * search (regex &expr, unsigned instance=0, unsigned flags=0) const
 
void set (const char *text)
 Set string object to text of a null terminated string.
 
void set (const char *text, char overflow, size_t offset, size_t size=0)
 Set a text field within our string object.
 
void set (size_t offset, const char *text, size_t size=0)
 Set a portion of the string object at a specified offset to a text string.
 
size_t size (void) const
 Get the size of currently allocated space for string.
 
const char * skip (const char *list, size_t offset=0) const
 Skip lead characters in the string.
 
void split (const char *pointer)
 Split the string by a pointer position.
 
void split (size_t offset)
 Split the string at a specific offset.
 
 String ()
 Create a new empty string object.
 
 String (const char *text)
 Create a string from null terminated text.
 
 String (const char *text, const char *end)
 Create a string for a substring.
 
 String (const char *text, size_t size)
 Create a string from null terminated text up to a maximum specified size.
 
 String (const String &existing)
 Construct a copy of a string object.
 
 String (size_t size)
 Create an empty string with a buffer pre-allocated to a specified size.
 
 String (size_t size, const char *format,...)
 Create a string by printf-like formating into a pre-allocated space of a specified size.
 
void strip (const char *list)
 Strip lead and trailing characters from the string.
 
double tod (char **pointer=NULL)
 Convert string to a double value.
 
char * token (char **last, const char *list, const char *quote=NULL, const char *end=NULL)
 A thread-safe token parsing routine for strings objects.
 
long tol (char **pointer=NULL)
 Convert string to a long value.
 
void trim (const char *list)
 Trim lead characters from the string.
 
void trim (size_t count=1)
 Trim lead characters from text.
 
bool unquote (const char *quote)
 Unquote a quoted string.
 
void upper (void)
 Convert string to upper case.
 
size_t vprintf (const char *format, va_list args)
 Print items into a string object.
 
virtual ~String ()
 Destroy string.
 
- Public Member Functions inherited from ucommon::ObjectProtocol
ObjectProtocolcopy (void)
 Retain (increase retention of) object when copying.
 
void operator++ (void)
 Increase retention operator.
 
void operator-- (void)
 Decrease retention operator.
 
virtual ~ObjectProtocol ()
 Required virtual destructor.
 

Static Public Member Functions

static memstringcreate (MemoryProtocol *pager, size_t size)
 Create a memory string with memory allocated from a pager.
 
static memstringcreate (size_t size)
 Create a memory string with memory allocated from the heap.
 
- Static Public Member Functions inherited from ucommon::String
static char * add (char *buffer, size_t size, const char *text)
 Safely append a null terminated string into an existing string in memory.
 
static char * add (char *buffer, size_t size, const char *text, size_t max)
 Safely append a null terminated string into an existing string in memory.
 
static String b64 (const uint8_t *binary, size_t size)
 Standard radix 64 string encoding.
 
static size_t b64count (const char *str, bool ws=false)
 
static size_t b64decode (uint8_t *binary, const char *string, size_t size, bool ws=false)
 Standard radix 64 decoding.
 
static size_t b64encode (char *string, const uint8_t *binary, size_t size, size_t width=0)
 Standard radix 64 encoding.
 
static size_t b64size (size_t size)
 
static unsigned ccount (const char *text, const char *list)
 Count instances of characters in a list in a text buffer.
 
static bool check (const char *string, size_t maximum, size_t minimum=0)
 Check if string is valid and in specific constraints.
 
static char * chop (char *text, const char *list)
 Strip trailing characters from the text string.
 
static int collate (const char *text1, const char *text2)
 
static int compare (const char *text1, const char *text2)
 Safe string collation function.
 
static int compare (const char *text1, const char *text2, size_t size)
 Depreciated string comparison function.
 
static char * copy (const char *text, size_t offset, size_t len)
 
static size_t count (const char *text)
 Safe version of strlen function.
 
static uint16_t crc16 (uint8_t *binary, size_t size)
 ccitt 16 bit crc for binary data.
 
static uint32_t crc24 (uint8_t *binary, size_t size)
 24 bit crc as used in openpgp.
 
static void cut (char *text, size_t offset, size_t len)
 
static char * dup (const char *text)
 Duplicate null terminated text into the heap.
 
static bool eq_case (const char *text1, const char *text2)
 Simple case insensitive equal test for strings.
 
static bool eq_case (const char *text1, const char *text2, size_t size)
 Simple case insensitive equal test for strings.
 
static bool equal (const char *text1, const char *text2)
 Simple equal test for strings.
 
static bool equal (const char *text1, const char *text2, size_t size)
 Simple equal test for strings.
 
static void erase (char *text)
 Erase string memory.
 
static char * fill (char *text, size_t size, char character)
 Fill a section of memory with a fixed text character.
 
static char * find (char *text, const char *list)
 Find the first occurrence of a character in a text buffer.
 
static const char * find (const char *text, const char *key, const char *optional)
 Find position of substring within a string.
 
static void fix (String &object)
 Fix and reset string object filler.
 
static String hex (const uint8_t *binary, size_t size)
 Convert binary data buffer into hex string.
 
static size_t hex2bin (const char *string, uint8_t *binary, size_t maxsize, bool wsflag=false)
 
static size_t hexcount (const char *str, bool ws=false)
 
static size_t hexdump (const uint8_t *binary, char *string, const char *format)
 Dump hex data to a string buffer.
 
static size_t hexpack (uint8_t *binary, const char *string, const char *format)
 Pack hex data from a string buffer.
 
static size_t hexsize (const char *format)
 
static const char * ifind (const char *text, const char *key, const char *optional)
 Find position of case insensitive substring within a string.
 
static char * left (const char *text, size_t size)
 Duplicate null terminated text of specific size to heap.
 
static void lower (char *text)
 Convert null terminated text to lower case.
 
static void paste (char *text, size_t max, size_t offset, const char *data, size_t len=0)
 
static const char * pos (const char *text, ssize_t offset)
 Compute position in string.
 
static char * rfind (char *text, const char *list)
 Find the last occurrence of a character in a text buffer.
 
static char * right (const char *text, size_t size)
 
static char * rset (char *buffer, size_t size, const char *text)
 Set a field in a null terminated string relative to the end of text.
 
static char * rskip (char *text, const char *list)
 Skip before trailing characters in a null terminated string.
 
static size_t seek (char *text, const char *list)
 Offset until next occurrence of character in a text or length.
 
static char * set (char *buffer, size_t size, const char *text)
 Safely set a null terminated string buffer in memory.
 
static char * set (char *buffer, size_t size, const char *text, size_t max)
 Safely set a null terminated string buffer in memory.
 
static char * skip (char *text, const char *list)
 Skip after lead characters in a null terminated string.
 
static char * strip (char *text, const char *list)
 Skip lead and remove trailing characters from a text string.
 
static void swap (String &object1, String &object2)
 Swap the cstring references between two strings.
 
static double tod (const char *text, char **pointer=NULL)
 Convert text to a double value.
 
static char * token (char *text, char **last, const char *list, const char *quote=NULL, const char *end=NULL)
 A thread-safe token parsing routine for null terminated strings.
 
static long tol (const char *text, char **pointer=NULL)
 Convert text to a long value.
 
static char * trim (char *text, const char *list)
 Return start of string after characters to trim from beginning.
 
static char * unquote (char *text, const char *quote)
 Unquote a quoted null terminated string.
 
static void upper (char *text)
 Convert null terminated text to upper case.
 

Static Public Attributes

static const size_t header = sizeof(String::cstring)
 
- Static Public Attributes inherited from ucommon::String
static const char eos = '\0'
 
static const size_t npos = ((size_t)-1)
 

Protected Member Functions

cstring * c_copy (void) const
 Return cstring to use in copy constructors.
 
- Protected Member Functions inherited from ucommon::String
cstring * create (size_t size) const
 Factory create a cstring object of specified size.
 
bool equal (const char *string) const
 Test if two string values are equal.
 
size_t getStringSize (void) const
 
virtual void retain (void)
 Increase retention of our reference counted cstring.
 

Additional Inherited Members

- Public Types inherited from ucommon::String
enum  { SENSITIVE = 0x00 , INSENSITIVE = 0x01 }
 This is an internal class which contains the actual string data along with some control fields. More...
 
- Protected Attributes inherited from ucommon::String
cstring * str
 cstring instance our object references.
 

Detailed Description

A string class that uses a cstring buffer that is fixed in memory.

This allows one to manipulate a fixed buffer of text in memory through the string class. The size of the memory used must include space for the overhead() size needed for the cstring object control data.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 1395 of file string.h.

Constructor & Destructor Documentation

◆ memstring()

ucommon::memstring::memstring ( void * memory,
size_t size )

Create an instance of a memory string.

Parameters
memoryto use for cstring object.
sizeof string. Total size must include space for overhead.

Member Function Documentation

◆ c_copy()

cstring * ucommon::memstring::c_copy ( void ) const
protectedvirtual

Return cstring to use in copy constructors.

Is virtual for memstring.

Returns
cstring for copy constructor.

Reimplemented from ucommon::String.

◆ create() [1/2]

static memstring * ucommon::memstring::create ( MemoryProtocol * pager,
size_t size )
static

Create a memory string with memory allocated from a pager.

Parameters
pagerto allocate memory from.
sizeof string to allocate. Automatically adds control size.

◆ create() [2/2]

static memstring * ucommon::memstring::create ( size_t size)
static

Create a memory string with memory allocated from the heap.

Parameters
sizeof string to allocate. Automatically adds control size.

◆ operator=() [1/2]

void ucommon::memstring::operator= ( const char * text)
inline

Assign null terminated text to our object.

Parameters
textto copy.

Definition at line 1421 of file string.h.

◆ operator=() [2/2]

void ucommon::memstring::operator= ( String & object)
inline

Assign the text of a string to our object.

Parameters
objectto copy text from.

Definition at line 1413 of file string.h.

Field Documentation

◆ header

const size_t ucommon::memstring::header = sizeof(String::cstring)
static

Definition at line 1398 of file string.h.


The documentation for this class was generated from the following file: