NetBurner 3.5.0
PDF Version
 
NBString Class Reference

Lightweight alternative to C++ CString class. More...

#include <nbstring.h>

Inherited by NBInterpolatedString.

Public Member Functions

 NBString ()
 Construct a NBString object.
 
 NBString (const NBString &str)
 Construct a new NBString object from an existing NBString object.
 
 NBString (const NBString &str, size_t pos, size_t len=npos)
 Construct a new NBString object from a substring of an existing NBString object.
 
 NBString (const char *s)
 Construct a NBString object from a character string (null terminated array of characters)
 
 NBString (const char *s, size_t n)
 Construct a NBString object from a character string up to the specified amount.
 
 ~NBString ()
 NBString destructor.
 
const char * c_str () const
 Method to pass a NBString as a constant char *.
 
NBString substr (size_t pos=0, size_t len=npos) const
 Creates a new NBString object from a substring of the existing NBString object.
 
int compare (const NBString &str) const
 Compares two NBString objects.
 
int compare (const char *s) const
 Compares the NBString object to a character string.
 
size_t find (const NBString str, size_t pos=0) const
 Find a substring within a NBString object.
 
size_t find (const char *str, size_t pos=0) const
 Find a substring within a character string.
 
size_t find (const char *s, size_t pos, size_t n) const
 Find a substring within a character string.
 
size_t find (char c, size_t pos=0) const
 Find the first occurence of a character within the NBString object.
 
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.
 
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.
 
size_t size () const
 Returns the current size of memory allocated for the string.
 
size_t length () const
 Returns the length of the string.
 
void clear ()
 Clear a NBString object and free allocated memory.
 
bool empty () const
 Check if a string is empty.
 
NBStringAppend (const char *str, size_t len)
 Append a string to an existing NBString object.
 
NBStringFdAppend (int fd, size_t len)
 Append from a file descriptor to an existing NBString object.
 
NBStringReserve (size_t len)
 Reserve an additional buffer amount.
 
int vsiprintf (const char *format, va_list &vl)
 Print to a string with formatting.
 
int sprintf (const char *format,...)
 sprintf to a string with formatting to a character array
 
int sprintf (NBString const format,...)
 sprintf to a string with formatting as a NBString object
 
int siprintf (const char *format,...)
 isprintf (integer) to a string with formatting to a character array
 
int siprintf (NBString const format,...)
 isprintf (integer) to a string with formatting to a NBString object
 
int stoi () const
 Parse the string and convert to an integer number.
 
long stol () const
 Parse the string value and convert to a long integer number.
 
unsigned int stoui () const
 Parse the string value and convert to a const integer number.
 
unsigned long stoul () const
 Parse the string value and convert to a const unsigned long integer number.
 
double stod () const
 Parse the string value and convert to a const double float number.
 
IPADDR to_ipaddr () const
 Parse the string value and convert to an IPADDR IP address.
 
size_t copy (char *s, size_t len, size_t pos=0) const
 Copy a substring, does not null terminate.
 
size_t strcopy (char *s, size_t len, size_t pos=0) const
 Copy a substring, with null termination.
 

Friends

void swap (NBString &x, NBString &y)
 Swaps the contents of two NBString objects.
 

Detailed Description

Lightweight alternative to C++ CString class.

Constructor & Destructor Documentation

◆ NBString() [1/4]

NBString::NBString ( const NBString & str)

Construct a new NBString object from an existing NBString object.

Parameters
strExisting NBString object

◆ NBString() [2/4]

NBString::NBString ( const NBString & str,
size_t pos,
size_t len = npos )

Construct a new NBString object from a substring of an existing NBString object.

Parameters
strExisting NBString object
posStarting position to copy
lenEnding position to copy

◆ NBString() [3/4]

NBString::NBString ( const char * s)

Construct a NBString object from a character string (null terminated array of characters)

Parameters
sString to initialize object

◆ NBString() [4/4]

NBString::NBString ( const char * s,
size_t n )

Construct a NBString object from a character string up to the specified amount.

Parameters
sString to initialize object
nNumber of characters to copy

Member Function Documentation

◆ Append()

NBString & NBString::Append ( const char * str,
size_t len )

Append a string to an existing NBString object.

Append a string to an existing NBString object

Parameters
strString to append
lenNumber of characters to append
Returns
The updated NBString object

◆ c_str()

const char * NBString::c_str ( ) const

Method to pass a NBString as a constant char *.

Will cause an allocation if it is pointing to a constant string longer than the currently allocated length.

Returns
A null terminated character array representing the string

◆ clear()

void NBString::clear ( )

Clear a NBString object and free allocated memory.

Clear a NBString object and free allocated memory

◆ compare() [1/2]

int NBString::compare ( const char * s) const

Compares the NBString object to a character string.

Parameters
sString to compare
Return values
0If identical
-1If NBString object is less than str
1If NBString object is greater than str

◆ compare() [2/2]

int NBString::compare ( const NBString & str) const

Compares two NBString objects.

Parameters
strNBString object to compare
Return values
0If identical
-1If NBString object is less than str
1If NBString object is greater than str

◆ copy()

size_t NBString::copy ( char * s,
size_t len,
size_t pos = 0 ) const

Copy a substring, does not null terminate.

Parameters
sDestination
lenSize of destination
posStarting position of copy
Returns
Number of bytes copied

◆ empty()

bool NBString::empty ( ) const

Check if a string is empty.

Check if a NBString object is empty

Return values
trueString is null
falseString contains data

◆ FdAppend()

NBString & NBString::FdAppend ( int fd,
size_t len )

Append from a file descriptor to an existing NBString object.

Append from a file descriptor to an existing NBString object

Parameters
fdFile descriptor to append from
lenNumber of characters to append
Returns
The updated NBString object

◆ find() [1/4]

size_t NBString::find ( char c,
size_t pos = 0 ) const

Find the first occurence of a character within the NBString object.

Parameters
cCharacter to search for
posStarting position to start search
Return values
>=0Position in string
-1If character not found

◆ find() [2/4]

size_t NBString::find ( const char * s,
size_t pos,
size_t n ) const

Find a substring within a character string.

Parameters
sString to search
posStarting position to start search
nNumber of characters that have to match
Return values
>=0Position in searched string
-1If substring not found

◆ find() [3/4]

size_t NBString::find ( const char * str,
size_t pos = 0 ) const

Find a substring within a character string.

Parameters
strString to search
posStarting position to start search
Return values
>=0Position in searched string
-1If substring not found

◆ find() [4/4]

size_t NBString::find ( const NBString str,
size_t pos = 0 ) const

Find a substring within a NBString object.

Parameters
strNString object to search
posStarting position to start search
Return values
>=0Position in searched string
-1If substring not found

◆ length()

size_t NBString::length ( ) const

Returns the length of the string.

Returns
The length of the string

◆ replace() [1/2]

size_t NBString::replace ( char c,
char rep,
size_t startPos = 0,
size_t end = 0 )

Replace all occurrences of all "<findStr>" characters within the NBString object.

Parameters
cCharacter to be replaced within the NBString
repCharacter to replace with
startPosStarting position to start replacing
endReplace all matching characters before this position, 0 = end of NBString
Return values
>0Number of Replaced Characters
-1If no matching character found

◆ replace() [2/2]

size_t NBString::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.

Parameters
findStrString of characters to be replaced within the NBString
repCharacter to replace with
startPosStarting position to start replacing
endReplace all matching characters before this position, 0 = end of NBString
Return values
>0Number of Replaced Characters
-1If no matching character found

◆ Reserve()

NBString & NBString::Reserve ( size_t len)

Reserve an additional buffer amount.

Reserve an additional buffer amount to prepare for a series of Appends

Parameters
lenNumber of additional characters to prepare to store
Returns
The updated NBString object

◆ siprintf() [1/2]

int NBString::siprintf ( const char * format,
... )

isprintf (integer) to a string with formatting to a character array

Parameters
formatprintf style formatting

◆ siprintf() [2/2]

int NBString::siprintf ( NBString const format,
... )

isprintf (integer) to a string with formatting to a NBString object

Parameters
formatprintf style formatting

◆ size()

size_t NBString::size ( ) const

Returns the current size of memory allocated for the string.

Returns
Total size of the object in bytes

◆ sprintf() [1/2]

int NBString::sprintf ( const char * format,
... )

sprintf to a string with formatting to a character array

Parameters
formatprintf style formatting

◆ sprintf() [2/2]

int NBString::sprintf ( NBString const format,
... )

sprintf to a string with formatting as a NBString object

Parameters
formatprintf style formatting

◆ stod()

double NBString::stod ( ) const

Parse the string value and convert to a const double float number.

Returns
const double float value

◆ stoi()

int NBString::stoi ( ) const

Parse the string and convert to an integer number.

Returns
integer value

◆ stol()

long NBString::stol ( ) const

Parse the string value and convert to a long integer number.

Returns
long integer value

◆ stoui()

unsigned int NBString::stoui ( ) const

Parse the string value and convert to a const integer number.

Returns
unsigned integer value

◆ stoul()

unsigned long NBString::stoul ( ) const

Parse the string value and convert to a const unsigned long integer number.

Returns
unsigned long integer value

◆ strcopy()

size_t NBString::strcopy ( char * s,
size_t len,
size_t pos = 0 ) const

Copy a substring, with null termination.

Parameters
sDestination
lenSize of destination
posStarting position of copy
Returns
Number of bytes copied

◆ substr()

NBString NBString::substr ( size_t pos = 0,
size_t len = npos ) const

Creates a new NBString object from a substring of the existing NBString object.

Parameters
posStarting position of substring
lenNumber of characters to copy
Returns
A NBString object

◆ to_ipaddr()

IPADDR NBString::to_ipaddr ( ) const

Parse the string value and convert to an IPADDR IP address.

Returns
const double float value

◆ vsiprintf()

int NBString::vsiprintf ( const char * format,
va_list & vl )

Print to a string with formatting.

Parameters
formatprintf style formatting
vlVariable argument list

Friends And Related Symbol Documentation

◆ swap

void swap ( NBString & x,
NBString & y )
friend

Swaps the contents of two NBString objects.

Useful for optimizing sorts. Friend function that takes two NBString objects as parameters and swaps their contents.


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