Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes
SString Class Reference

#include <string.h>

Inheritance diagram for SString:
Inheritance graph
[legend]
Collaboration diagram for SString:
Collaboration graph
[legend]

Public Types

typedef size_t size_type
 

Public Member Functions

 SString ()
 Create an empty streamable string ready for input. More...
 
 SString (const SString &from)
 Copy constructor. More...
 
 ~SString ()
 Cancel out the object. More...
 
char * text (void) const
 Alternate get text method. More...
 
size_t size (void) const
 Get actual length of string data. More...
 
size_t length (void) const
 Get length as if null terminated string. More...
 
const char * getIndex (size_t index) const
 Get a string pointer to string content based on an indexed offset. More...
 
char * getText (void) const
 Get the text of a string. More...
 
long getValue (long defvalue=0l) const
 Get the value of a string. More...
 
bool getBool (bool defbool=false) const
 Get the bool flag of a string. More...
 
const size_t getLength (void) const
 Get the assigned length of string. More...
 
const size_t getSize (void) const
 Get the allocation size of the string variable. More...
 
bool isEmpty (void) const
 Return true if string is empty. More...
 
void resize (size_t size)
 Re-allocate buffer space for string. More...
 
void clear (void)
 Clear the contents of the entire string. More...
 
char at (ssize_t offset) const
 Return a character at a known offset. More...
 
unsigned count (const String &s, size_t offset=0) const
 Count the number of occurences of a specific string within our string. More...
 
unsigned count (const char *s, size_t offset=0, size_t len=0) const
 Count the number of occurrences of a specific text pattern within our string. More...
 
String token (const char *delim=" \t\n\r", size_t offset=0)
 Extract a new string as a token from the current string. More...
 
size_t find (const String &s, size_t offset=0, unsigned instance=1) const
 Find the index to the nth instance of a substring in our string. More...
 
size_t find (const char *s, size_t offset=0, size_t len=0, unsigned count=1) const
 Find the index to the nth instance of text in our string. More...
 
size_t find (unsigned instance, const char *text, size_t offset=0, size_t len=0) const
 A more convenient version of find for nth occurences, by putting the instance first. More...
 
size_t find (unsigned instance, const String &string, size_t offset=0) const
 A more convenient version of find for nth occurences, by putting the instance first. More...
 
size_t rfind (const String &s, size_t offset=0) const
 Find last occurence of a substring in our string. More...
 
size_t rfind (const char *s, size_t offset=0, size_t len=0) const
 Find last occurence of a text in our string. More...
 
void trim (const char *cs)
 Trim trailing characters from a string. More...
 
void trim (size_t count)
 Trim n trailing characters from a string. More...
 
void chop (const char *cs)
 Chop leading characters from a string. More...
 
void chop (size_t chars)
 Chop n leading characters from a string. More...
 
void strip (const char *cs)
 Strip lead and trailing characters from a string. More...
 
void erase (size_t start, size_t len=npos)
 Erase a portion of string. More...
 
void insert (size_t start, const char *text, size_t len=0)
 Insert text into a string. More...
 
void insert (size_t start, const String &str)
 Insert other string into our string. More...
 
void replace (size_t start, size_t len, const char *text, size_t count=0)
 Replace text at a specific position in the string with new text. More...
 
void replace (size_t start, size_t len, const String &string)
 Replace text at a specific position in the string with new string,. More...
 
String substr (size_t start, size_t len) const
 Return a new string that contains a specific substring of the current string. More...
 
const char *() index (size_t ind) const
 Return an indexed string based on the index, such as from a find. More...
 
void compact (void)
 Reduce the size of the string allocation to the minimum needed based on the current effective length. More...
 
char * c_str (void) const
 Old ANSI C++ compatible string pointer extraction. More...
 
 operator char * () const
 Get our string data through dereference operator. More...
 
bool operator! (void) const
 Logical test for string empty. More...
 
char * data (void) const
 Alternate get text method. More...
 
size_t capacity (void) const
 Get space allocated to hold current string. More...
 
bool empty (void) const
 Return true if string is empty. More...
 
void append (const char *str, size_t count=0)
 Append text to the end of the current string. More...
 
void append (const char *str, size_t offset, size_t count)
 Append text into the current string. More...
 
void append (const String &str)
 Append string to the end of the current string. More...
 
void add (char c)
 Add a character to the end of a string. More...
 
const char operator[] (unsigned ind) const
 Extract a character by array indexing. More...
 
Stringoperator+= (const String &str)
 Append operator. More...
 
Stringoperator+= (char c)
 Append operator. More...
 
Stringoperator+= (const char *str)
 Append operator. More...
 
Stringoperator+= (const std::string &str)
 Append operator. More...
 
bool operator< (const String &str) const
 
bool operator< (const char *str) const
 
bool operator> (const String &str) const
 
bool operator> (const char *str) const
 
bool operator<= (const String &str) const
 
bool operator<= (const char *str) const
 
bool operator>= (const String &str) const
 
bool operator>= (const char *str) const
 
bool operator== (const String &str) const
 
bool operator== (const char *str) const
 
bool operator!= (const String &str) const
 
bool operator!= (const char *str) const
 
bool operator*= (const String &str) const
 Test if string is contained in our string. More...
 
bool operator*= (const char *str) const
 Test if text is contained in our string. More...
 

Static Public Attributes

static const size_t npos
 

Protected Member Functions

int overflow (int c)
 This is the streambuf function that actually outputs the data to the string. More...
 
bool isBig (void) const
 Determine if string is allocated in local variable or an external reference. More...
 
const char * set (const char *str, size_t len=0)
 Set the content of the string variable to the specified string value, and use smart re-allocation strategies if appropriate to shrink the size of the variable. More...
 
void set (const String &str)
 Set the content of the string variable to that of another variable. More...
 
void copy (const String &str)
 Impliment the copy constructor, used internally. More...
 
void init (void)
 Used to initialize a string object. More...
 
size_t setSize (size_t size)
 Set the size of allocated space in the string variable (capacity) to a known value. More...
 
void setLength (size_t len)
 Set the length value of the string content. More...
 
virtual int compare (const char *text, size_t len=0, size_t index=0) const
 A derivable low level comparison operator. More...
 
size_t search (const char *text, size_t clen=0, size_t offset=0) const
 An internal method used to search for a substring starting at a known offset. More...
 

Static Protected Member Functions

static char * getSpace (size_t size)
 Used to fetch memory, if needed, based on the size, from the pager, or the system heap. More...
 

Static Protected Attributes

static const unsigned minsize
 
static const unsigned slotsize
 
static const unsigned pagesize
 
static const unsigned slotlimit
 
static const unsigned slotcount
 

Detailed Description

Definition at line 845 of file string.h.

Member Typedef Documentation

typedef size_t String::size_type
inherited

Definition at line 218 of file string.h.

Constructor & Destructor Documentation

SString::SString ( )

Create an empty streamable string ready for input.

SString::SString ( const SString from)

Copy constructor.

SString::~SString ( )

Cancel out the object.

Member Function Documentation

void String::add ( char  c)
inherited

Add a character to the end of a string.

Parameters
cchar to add.
void String::append ( const char *  str,
size_t  count = 0 
)
inherited

Append text to the end of the current string.

Parameters
strtext to append.
countsize of text to append.
void String::append ( const char *  str,
size_t  offset,
size_t  count 
)
inherited

Append text into the current string.

Parameters
strtext to append.
offsetoffset to overlay.
countsize of text to append.
void String::append ( const String str)
inherited

Append string to the end of the current string.

Parameters
strstring to append.
char String::at ( ssize_t  offset) const
inherited

Return a character at a known offset.

Returns
character at offset.
char* String::c_str ( void  ) const
inlineinherited

Old ANSI C++ compatible string pointer extraction.

Returns
string data.

Definition at line 567 of file string.h.

size_t String::capacity ( void  ) const
inlineinherited

Get space allocated to hold current string.

Returns
space of memory buffer from heap or local.

Definition at line 623 of file string.h.

void String::chop ( const char *  cs)
inlineinherited

Chop leading characters from a string.

Parameters
cslist of chars to chop.

Definition at line 440 of file string.h.

void String::chop ( size_t  chars)
inlineinherited

Chop n leading characters from a string.

Parameters
charscount to chop.

Definition at line 455 of file string.h.

void String::clear ( void  )
inherited

Clear the contents of the entire string.

void String::compact ( void  )
inlineinherited

Reduce the size of the string allocation to the minimum needed based on the current effective length.

Definition at line 559 of file string.h.

virtual int String::compare ( const char *  text,
size_t  len = 0,
size_t  index = 0 
) const
protectedvirtualinherited

A derivable low level comparison operator.

This can be used to create custom comparison data types in derived string classes.

Returns
0 if match, or value for ordering.
Parameters
texttext to compare.
lenlength of text to compare.
indexoffset from start of string, used in searchs.
void String::copy ( const String str)
protectedinherited

Impliment the copy constructor, used internally.

Will always create a minimum sized string allocation.

Parameters
strstring to copy from.
unsigned String::count ( const String s,
size_t  offset = 0 
) const
inherited

Count the number of occurences of a specific string within our string.

Returns
count of instances.
Parameters
sstring to test.
offsetoffset to start from.
unsigned String::count ( const char *  s,
size_t  offset = 0,
size_t  len = 0 
) const
inherited

Count the number of occurrences of a specific text pattern within our string.

Returns
count of instances.
Parameters
stext pattern to find
offsetoffset to start from.
lenlength of text pattern if specified.
char* String::data ( void  ) const
inlineinherited

Alternate get text method.

Returns
string data.

Definition at line 599 of file string.h.

bool String::empty ( void  ) const
inlineinherited

Return true if string is empty.

Definition at line 629 of file string.h.

void String::erase ( size_t  start,
size_t  len = npos 
)
inherited

Erase a portion of string.

Parameters
startstarting index to erase from.
lennumber of characters to erase.
size_t String::find ( const String s,
size_t  offset = 0,
unsigned  instance = 1 
) const
inherited

Find the index to the nth instance of a substring in our string.

Returns
index of found substring.
Parameters
sstring to search for.
offsetoffset to start at.
instanceinstance to look for.
size_t String::find ( const char *  s,
size_t  offset = 0,
size_t  len = 0,
unsigned  count = 1 
) const
inherited

Find the index to the nth instance of text in our string.

Returns
index of found substring.
Parameters
sstring to search for.
offsetoffset to start at.
lensize of string text.
countinstance to look for.
size_t String::find ( unsigned  instance,
const char *  text,
size_t  offset = 0,
size_t  len = 0 
) const
inlineinherited

A more convenient version of find for nth occurences, by putting the instance first.

Parameters
instancenth instance to look for.
texttext to look for.
offsetoffset to start at.
lenlength of text.

Definition at line 520 of file string.h.

size_t String::find ( unsigned  instance,
const String string,
size_t  offset = 0 
) const
inlineinherited

A more convenient version of find for nth occurences, by putting the instance first.

Parameters
instancenth instance to look for.
stringreference to look for.
offsetoffset to start at.

Definition at line 531 of file string.h.

bool String::getBool ( bool  defbool = false) const
inherited

Get the bool flag of a string.

Returns
boolean value.
const char* String::getIndex ( size_t  index) const
inherited

Get a string pointer to string content based on an indexed offset.

A NULL is returned if the index is outsize of range.

Returns
string content or NULL if invalid index.
Parameters
index
const size_t String::getLength ( void  ) const
inherited

Get the assigned length of string.

Returns
string length.
const size_t String::getSize ( void  ) const
inherited

Get the allocation size of the string variable.

Returns
allocation size.
static char* String::getSpace ( size_t  size)
staticprotectedinherited

Used to fetch memory, if needed, based on the size, from the pager, or the system heap.

Returns
string pointer to space.
Parameters
sizeof space needed.
char* String::getText ( void  ) const
inherited

Get the text of a string.

Returns
string content.
long String::getValue ( long  defvalue = 0l) const
inherited

Get the value of a string.

Returns
string value as number.
const char*() String::index ( size_t  ind) const
inlineinherited

Return an indexed string based on the index, such as from a find.

If out of range, a NULL string is returned.

Returns
pointer to string data from our string,
Parameters
indindex or offset to use.

Definition at line 552 of file string.h.

void String::init ( void  )
protectedinherited

Used to initialize a string object.

void String::insert ( size_t  start,
const char *  text,
size_t  len = 0 
)
inherited

Insert text into a string.

Parameters
startstarting offset to insert at.
texttext to insert.
lensize of text to insert.
void String::insert ( size_t  start,
const String str 
)
inherited

Insert other string into our string.

Parameters
startstring offset to insert at.
strstring to insert.
bool String::isBig ( void  ) const
inlineprotectedinherited

Determine if string is allocated in local variable or an external reference.

Returns
true if external heap is used.

Definition at line 122 of file string.h.

bool String::isEmpty ( void  ) const
inherited

Return true if string is empty.

Returns
true if string is empty string.
size_t String::length ( void  ) const
inlineinherited

Get length as if null terminated string.

Returns
cstring length.

Definition at line 607 of file string.h.

String::operator char * ( ) const
inlineinherited

Get our string data through dereference operator.

Returns
string data.

Definition at line 575 of file string.h.

bool String::operator! ( void  ) const
inlineinherited

Logical test for string empty.

Returns
true if is empty.

Definition at line 583 of file string.h.

bool String::operator!= ( const String str) const
inherited
bool String::operator!= ( const char *  str) const
inherited
bool String::operator*= ( const String str) const
inherited

Test if string is contained in our string.

bool String::operator*= ( const char *  str) const
inherited

Test if text is contained in our string.

String& String::operator+= ( const String str)
inlineinherited

Append operator.

Definition at line 703 of file string.h.

String& String::operator+= ( char  c)
inlineinherited

Append operator.

Definition at line 709 of file string.h.

String& String::operator+= ( const char *  str)
inlineinherited

Append operator.

Definition at line 715 of file string.h.

String& String::operator+= ( const std::string &  str)
inlineinherited

Append operator.

Definition at line 721 of file string.h.

bool String::operator< ( const String str) const
inherited
bool String::operator< ( const char *  str) const
inherited
bool String::operator<= ( const String str) const
inherited
bool String::operator<= ( const char *  str) const
inherited
bool String::operator== ( const String str) const
inherited
bool String::operator== ( const char *  str) const
inherited
bool String::operator> ( const String str) const
inherited
bool String::operator> ( const char *  str) const
inherited
bool String::operator>= ( const String str) const
inherited
bool String::operator>= ( const char *  str) const
inherited
const char String::operator[] ( unsigned  ind) const
inlineinherited

Extract a character by array indexing.

Returns
character code.

Definition at line 678 of file string.h.

int SString::overflow ( int  c)
protected

This is the streambuf function that actually outputs the data to the string.

Since all output should be done with the standard ostream operators, this function should never be called directly.

void String::replace ( size_t  start,
size_t  len,
const char *  text,
size_t  count = 0 
)
inherited

Replace text at a specific position in the string with new text.

Parameters
startstarting offset to replace at.
lenlength of text to remove.
texttext to replace with.
countsize of replacement text.
void String::replace ( size_t  start,
size_t  len,
const String string 
)
inherited

Replace text at a specific position in the string with new string,.

Parameters
startstarting offset to replace at.
lenlength of text to remove.
stringreference to replace with.
void String::resize ( size_t  size)
inherited

Re-allocate buffer space for string.

Parameters
sizenew size to use.
size_t String::rfind ( const String s,
size_t  offset = 0 
) const
inherited

Find last occurence of a substring in our string.

Returns
index of last instance found,
Parameters
sstring to search for.
offsetoffset to start from.
size_t String::rfind ( const char *  s,
size_t  offset = 0,
size_t  len = 0 
) const
inherited

Find last occurence of a text in our string.

Returns
index of last instance found,
Parameters
sstring to search for.
offsetoffset to start from.
lensize of string to look for.
size_t String::search ( const char *  text,
size_t  clen = 0,
size_t  offset = 0 
) const
protectedinherited

An internal method used to search for a substring starting at a known offset.

Used by find and count methods.

Returns
npos if fails, or offset to text found.
Parameters
texttext to search for.
clenlength of search text.
offsetoffset to start from.
const char* String::set ( const char *  str,
size_t  len = 0 
)
protectedinherited

Set the content of the string variable to the specified string value, and use smart re-allocation strategies if appropriate to shrink the size of the variable.

Parameters
strstring to set.
lenlength of string if passed.
void String::set ( const String str)
protectedinherited

Set the content of the string variable to that of another variable.

Uses the string set method.

Parameters
strstring to copy from.
void String::setLength ( size_t  len)
protectedinherited

Set the length value of the string content.

Parameters
lensize in bytes.
size_t String::setSize ( size_t  size)
protectedinherited

Set the size of allocated space in the string variable (capacity) to a known value.

The value is recomputed and adjusted based on allocation method.

Parameters
sizein bytes.
size_t String::size ( void  ) const
inlineinherited

Get actual length of string data.

Returns
actual size of string.

Definition at line 615 of file string.h.

void String::strip ( const char *  cs)
inherited

Strip lead and trailing characters from a string.

Parameters
cslist of chars to strip.
String String::substr ( size_t  start,
size_t  len 
) const
inlineinherited

Return a new string that contains a specific substring of the current string.

Returns
new string.
Parameters
startstarting offset for extracted substring.
lenlength of substring.

Definition at line 542 of file string.h.

char* String::text ( void  ) const
inlineinherited

Alternate get text method.

Returns
string data.

Definition at line 591 of file string.h.

String String::token ( const char *  delim = " \t\n\r",
size_t  offset = 0 
)
inherited

Extract a new string as a token from the current string.

Returns
string containing token.
Parameters
delimdeliminator characters.
offsetoffset to start from.
void String::trim ( const char *  cs)
inlineinherited

Trim trailing characters from a string.

Parameters
cslist of chars to trim.

Definition at line 432 of file string.h.

void String::trim ( size_t  count)
inherited

Trim n trailing characters from a string.

Parameters
countnumber of bytes to trim.

Field Documentation

bool String::big
inherited

Definition at line 107 of file string.h.

struct { ... } String::bigstring
size_t String::length
inherited

Definition at line 102 of file string.h.

char String::length
inherited

Definition at line 106 of file string.h.

struct { ... } String::ministring
const unsigned String::minsize
staticprotectedinherited

Definition at line 80 of file string.h.

const size_t String::npos
staticinherited

Definition at line 216 of file string.h.

const unsigned String::pagesize
staticprotectedinherited

Definition at line 82 of file string.h.

size_t String::size
inherited

Definition at line 101 of file string.h.

const unsigned String::slotcount
staticprotectedinherited

Definition at line 84 of file string.h.

const unsigned String::slotlimit
staticprotectedinherited

Definition at line 83 of file string.h.

const unsigned String::slotsize
staticprotectedinherited

Definition at line 81 of file string.h.

char* String::text
inherited

Definition at line 100 of file string.h.

char String::text[(sizeof(char *)+(sizeof(size_t)*2)+1)]
inherited

Definition at line 105 of file string.h.


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