SYNOPSIS

#include <string.h>

Inherited by ost::SString.

Public Types

typedef size_t size_type

Public Member Functions

String ()

Construct an empty string. String (const String &original)

Copy constructor. String (const char *str)

Create a string from a cstring. String (std::string string)

Create a String from std::string. String (const String &str, size_t offset, size_t len=npos)

Create a new string from a subset of another string. String (size_t size, const char *format,...)

Create a string from formatted text input. String (size_t count, const char fill= ' ')

Fill a new string with character data. virtual ~String ()

Destroy the string... const char * getIndex (size_t index) const

Get a string pointer to string content based on an indexed offset. char * getText (void) const

Get the text of a string. long getValue (long defvalue=0l) const

Get the value of a string. bool getBool (bool defbool=false) const

Get the bool flag of a string. const size_t getLength (void) const

Get the assigned length of string. const size_t getSize (void) const

Get the allocation size of the string variable. bool isEmpty (void) const

Return true if string is empty. void resize (size_t size)

Re-allocate buffer space for string. void clear (void)

Clear the contents of the entire string. char at (ssize_t offset) const

Return a character at a known offset. unsigned count (const String &s, size_t offset=0) const

Count the number of occurences of a specific string within our string. 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. String token (const char *delim=' \t\n\r', size_t offset=0)

Extract a new string as a token from the current string. 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. size_t rfind (const String &s, size_t offset=0) const

Find last occurence of a substring in our string. 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. size_t rfind (const char *s, size_t offset=0, size_t len=0) const

Find last occurence of a text in our string. void trim (const char *cs)

Trim trailing characters from a string. void chop (const char *cs)

Chop leading characters from a string. void strip (const char *cs)

Strip lead and trailing characters from a string. void chop (size_t chars)

Chop n leading characters from a string. void trim (size_t count)

Trim n trailing characters from a string. void erase (size_t start, size_t len=npos)

Erase a portion of string. void insert (size_t start, const char *text, size_t len=0)

Insert text into a string. void insert (size_t start, const String &str)

Insert other string into our string. 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. void replace (size_t start, size_t len, const String &string)

Replace text at a specific position in the string with new string,. 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. 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. String substr (size_t start, size_t len) const

Return a new string that contains a specific substring of the current string. const char *() index (size_t ind) const

Return an indexed string based on the index, such as from a find. void compact (void)

Reduce the size of the string allocation to the minimum needed based on the current effective length. char * c_str (void) const

Old ANSI C++ compatible string pointer extraction. operator char * () const

Get our string data through dereference operator. bool operator! (void) const

Logical test for string empty. char * text (void) const

Alternate get text method. char * data (void) const

Alternate get text method. size_t length (void) const

Get length as if null terminated string. size_t size (void) const

Get actual length of string data. size_t capacity (void) const

Get space allocated to hold current string. bool empty (void) const

Return true if string is empty. void append (const char *str, size_t count=0)

Append text to the end of the current string. void append (size_t size, const char *format,...)

Append formatted text to the end of the current string. void append (const char *str, size_t offset, size_t count)

Append text into the current string. void add (char c)

Add a character to the end of a string. void append (const String &str)

Append string to the end of the current string. const char operator[] (unsigned ind) const

Extract a character by array indexing. const char * operator= (const char *str)

Assign our string for c string. String & operator+= (const String &str)

Append operator. String & operator+= (char c)

Append operator. String & operator+= (const char *str)

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

Append operator. 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

String & operator+= (int i)

Append operator. String & operator+= (unsigned int i)

String & operator+= (long l)

String & operator+= (unsigned long l)

String & operator+= (float f)

String & operator+= (double d)

String & operator+= (short s)

String & operator+= (unsigned short s)

String & operator= (int i)

Assignment operator. String & operator= (unsigned int i)

String & operator= (long l)

String & operator= (unsigned long l)

String & operator= (float f)

String & operator= (double d)

String & operator= (short s)

String & operator= (unsigned short s)

String & operator= (const String &original)

bool operator*= (const String &str) const

Test if string is contained in our string. bool operator*= (const char *str) const

Test if text is contained in our string.

Static Public Attributes

static const size_t npos

Protected Member Functions

bool isBig (void) const

Determine if string is allocated in local variable or an external reference. 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. void set (const String &str)

Set the content of the string variable to that of another variable. const char * set (size_t size, const char *format,...)

Set the content of the string variable to that of a formatted printf style string. void copy (const String &str)

Impliment the copy constructor, used internally. void init (void)

Used to initialize a string object. size_t setSize (size_t size)

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

Set the length value of the string content. virtual int compare (const char *text, size_t len=0, size_t index=0) const

A derivable low level comparison operator. 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.

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.

Static Protected Attributes

static const unsigned minsize

static const unsigned slotsize

static const unsigned pagesize

static const unsigned slotlimit

static const unsigned slotcount

Friends

class StringObject

class MemPager

__EXPORT String operator+ (const String &s1, const String &s2)

Add two strings and return a temporary object. __EXPORT String operator+ (const String &s1, const char *s2)

__EXPORT String operator+ (const char *s1, const String &s2)

__EXPORT String operator+ (const String &s1, const char c2)

__EXPORT String operator+ (const char c1, const String &s2)

__EXPORT std::istream & getline (std::istream &is, String &str, char delim= '\n', size_t size=0)

Fetch input from a std::istream into the current string variable until either the string variable is filled (based on current length) or the deliminator is read. __EXPORT std::ostream & operator<< (std::ostream &os, const String &str)

Stream the content of our string variable directly to a C++ streaming source. std::istream & operator>> (std::istream &is, String &str)

Stream input into our variable. __EXPORT int strprintf (String &str, size_t size, const char *format,...)

Print values directly into a string variable.

Detailed Description

This is a generic and portable string class.

It uses optimized memory allocation strategies to efficiently handle smaller string content by grouping strings into 32 byte aligned slots that can be re-allocated from a free list directly.

While meant to cover the basic functionality of the ANSI C++ string class in form and function, this class offers some important enhancements, including the ability to derive class type specific versions of itself. The latter might be used to derive a unicode string, a string for data and time data types, or to add case insensitive comparisons, for example.

Author:

David Sugar [email protected] Generic string class.

Member Typedef Documentation

typedef size_t \fBost::String::size_type\fP

Constructor & Destructor Documentation

ost::String::String ()

Construct an empty string.

ost::String::String (const \fBString\fP &original)

Copy constructor.

Parameters:

original string to copy from.

ost::String::String (const char *str)

Create a string from a cstring.

Parameters:

str text to set with.

ost::String::String (std::stringstring)

Create a String from std::string.

Parameters:

string from std::string to copy from.

ost::String::String (const \fBString\fP &str, size_toffset, size_tlen = \fC\fBnpos\fP\fP)

Create a new string from a subset of another string.

Parameters:

str reference of source string.

offset offset to start of data in prior string.

len length of our substring.

ost::String::String (size_tsize, const char *format, ...)

Create a string from formatted text input.

Parameters:

size to allocate for our new string.

format of data to input.

ost::String::String (size_tcount, const charfill = \fC' '\fP)

Fill a new string with character data.

Parameters:

count size of new string.

fill char to fill string with.

virtual ost::String::~String ()\fC [virtual]\fP

Destroy the string...

Member Function Documentation

void ost::String::add (charc)

Add a character to the end of a string.

Parameters:

c char to add.

void ost::String::append (const char *str, size_tcount = \fC0\fP)

Append text to the end of the current string.

Parameters:

str text to append.

count size of text to append.

void ost::String::append (size_tsize, const char *format, ...)

Append formatted text to the end of the current string.

Parameters:

size size of text to append.

format of data to append.

void ost::String::append (const char *str, size_toffset, size_tcount)

Append text into the current string.

Parameters:

str text to append.

offset offset to overlay.

count size of text to append.

void ost::String::append (const \fBString\fP &str)

Append string to the end of the current string.

Parameters:

str string to append.

char ost::String::at (ssize_toffset) const

Return a character at a known offset.

Returns:

character at offset.

char* ost::String::c_str (void) const\fC [inline]\fP

Old ANSI C++ compatible string pointer extraction.

Returns:

string data.

size_t ost::String::capacity (void) const\fC [inline]\fP

Get space allocated to hold current string.

Returns:

space of memory buffer from heap or local.

void ost::String::chop (const char *cs)\fC [inline]\fP

Chop leading characters from a string.

Parameters:

cs list of chars to chop.

References ost::strchop().

void ost::String::chop (size_tchars)\fC [inline]\fP

Chop n leading characters from a string.

Parameters:

chars count to chop.

void ost::String::clear (void)

Clear the contents of the entire string.

void ost::String::compact (void)\fC [inline]\fP

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

virtual int ost::String::compare (const char *text, size_tlen = \fC0\fP, size_tindex = \fC0\fP) const\fC [protected]\fP, \fC [virtual]\fP

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:

text text to compare.

len length of text to compare.

index offset from start of string, used in searchs.

void ost::String::copy (const \fBString\fP &str)\fC [protected]\fP

Impliment the copy constructor, used internally. Will always create a minimum sized string allocation.

Parameters:

str string to copy from.

unsigned ost::String::count (const \fBString\fP &s, size_toffset = \fC0\fP) const

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

Returns:

count of instances.

Parameters:

s string to test.

offset offset to start from.

unsigned ost::String::count (const char *s, size_toffset = \fC0\fP, size_tlen = \fC0\fP) const

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

Returns:

count of instances.

Parameters:

s text pattern to find

offset offset to start from.

len length of text pattern if specified.

char* ost::String::data (void) const\fC [inline]\fP

Alternate get text method.

Returns:

string data.

bool ost::String::empty (void) const\fC [inline]\fP

Return true if string is empty.

void ost::String::erase (size_tstart, size_tlen = \fC\fBnpos\fP\fP)

Erase a portion of string.

Parameters:

start starting index to erase from.

len number of characters to erase.

size_t ost::String::find (const \fBString\fP &s, size_toffset = \fC0\fP, unsignedinstance = \fC1\fP) const

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

Returns:

index of found substring.

Parameters:

s string to search for.

offset offset to start at.

instance instance to look for.

size_t ost::String::find (const char *s, size_toffset = \fC0\fP, size_tlen = \fC0\fP, unsignedcount = \fC1\fP) const

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

Returns:

index of found substring.

Parameters:

s string to search for.

offset offset to start at.

len size of string text.

count instance to look for.

size_t ost::String::find (unsignedinstance, const char *text, size_toffset = \fC0\fP, size_tlen = \fC0\fP) const\fC [inline]\fP

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

Parameters:

instance nth instance to look for.

text text to look for.

offset offset to start at.

len length of text.

References ost::find().

size_t ost::String::find (unsignedinstance, const \fBString\fP &string, size_toffset = \fC0\fP) const\fC [inline]\fP

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

Parameters:

instance nth instance to look for.

string reference to look for.

offset offset to start at.

References ost::find().

bool ost::String::getBool (booldefbool = \fCfalse\fP) const

Get the bool flag of a string.

Returns:

boolean value.

const char* ost::String::getIndex (size_tindex) const

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 ost::String::getLength (void) const

Get the assigned length of string.

Returns:

string length.

const size_t ost::String::getSize (void) const

Get the allocation size of the string variable.

Returns:

allocation size.

static char* ost::String::getSpace (size_tsize)\fC [static]\fP, \fC [protected]\fP

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

Returns:

string pointer to space.

Parameters:

size of space needed.

char* ost::String::getText (void) const

Get the text of a string.

Returns:

string content.

long ost::String::getValue (longdefvalue = \fC0l\fP) const

Get the value of a string.

Returns:

string value as number.

const char*() ost::String::index (size_tind) const\fC [inline]\fP

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:

ind index or offset to use.

void ost::String::init (void)\fC [protected]\fP

Used to initialize a string object.

void ost::String::insert (size_tstart, const char *text, size_tlen = \fC0\fP)

Insert text into a string.

Parameters:

start starting offset to insert at.

text text to insert.

len size of text to insert.

void ost::String::insert (size_tstart, const \fBString\fP &str)

Insert other string into our string.

Parameters:

start string offset to insert at.

str string to insert.

bool ost::String::isBig (void) const\fC [inline]\fP, \fC [protected]\fP

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

Returns:

true if external heap is used.

bool ost::String::isEmpty (void) const

Return true if string is empty.

Returns:

true if string is empty string.

size_t ost::String::length (void) const\fC [inline]\fP

Get length as if null terminated string.

Returns:

cstring length.

ost::String::operator char * () const\fC [inline]\fP

Get our string data through dereference operator.

Returns:

string data.

bool ost::String::operator! (void) const\fC [inline]\fP

Logical test for string empty.

Returns:

true if is empty.

bool \fBost::String::operator!\fP= (const \fBString\fP &str) const

bool \fBost::String::operator!\fP= (const char *str) const

bool ost::String::operator*= (const \fBString\fP &str) const

Test if string is contained in our string.

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

Test if text is contained in our string.

\fBString\fP& ost::String::operator+= (const \fBString\fP &str)\fC [inline]\fP

Append operator.

\fBString\fP& ost::String::operator+= (charc)\fC [inline]\fP

Append operator.

\fBString\fP& ost::String::operator+= (const char *str)\fC [inline]\fP

Append operator.

\fBString\fP& ost::String::operator+= (const std::string &str)\fC [inline]\fP

Append operator.

\fBString\fP& ost::String::operator+= (inti)\fC [inline]\fP

Append operator.

\fBString\fP& ost::String::operator+= (unsigned inti)\fC [inline]\fP

\fBString\fP& ost::String::operator+= (longl)\fC [inline]\fP

\fBString\fP& ost::String::operator+= (unsigned longl)\fC [inline]\fP

\fBString\fP& ost::String::operator+= (floatf)\fC [inline]\fP

\fBString\fP& ost::String::operator+= (doubled)\fC [inline]\fP

\fBString\fP& ost::String::operator+= (shorts)\fC [inline]\fP

\fBString\fP& ost::String::operator+= (unsigned shorts)\fC [inline]\fP

bool ost::String::operator< (const \fBString\fP &str) const

bool ost::String::operator< (const char *str) const

bool ost::String::operator<= (const \fBString\fP &str) const

bool ost::String::operator<= (const char *str) const

const char* ost::String::operator= (const char *str)\fC [inline]\fP

Assign our string for c string.

\fBString\fP& ost::String::operator= (inti)\fC [inline]\fP

Assignment operator.

\fBString\fP& ost::String::operator= (unsigned inti)\fC [inline]\fP

\fBString\fP& ost::String::operator= (longl)\fC [inline]\fP

\fBString\fP& ost::String::operator= (unsigned longl)\fC [inline]\fP

\fBString\fP& ost::String::operator= (floatf)\fC [inline]\fP

\fBString\fP& ost::String::operator= (doubled)\fC [inline]\fP

\fBString\fP& ost::String::operator= (shorts)\fC [inline]\fP

\fBString\fP& ost::String::operator= (unsigned shorts)\fC [inline]\fP

\fBString\fP& ost::String::operator= (const \fBString\fP &original)\fC [inline]\fP

bool ost::String::operator== (const \fBString\fP &str) const

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

bool ost::String::operator> (const \fBString\fP &str) const

bool ost::String::operator> (const char *str) const

bool ost::String::operator>= (const \fBString\fP &str) const

bool ost::String::operator>= (const char *str) const

const char ost::String::operator[] (unsignedind) const\fC [inline]\fP

Extract a character by array indexing.

Returns:

character code.

void ost::String::replace (size_tstart, size_tlen, const char *text, size_tcount = \fC0\fP)

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

Parameters:

start starting offset to replace at.

len length of text to remove.

text text to replace with.

count size of replacement text.

void ost::String::replace (size_tstart, size_tlen, const \fBString\fP &string)

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

Parameters:

start starting offset to replace at.

len length of text to remove.

string reference to replace with.

void ost::String::resize (size_tsize)

Re-allocate buffer space for string.

Parameters:

size new size to use.

size_t ost::String::rfind (const \fBString\fP &s, size_toffset = \fC0\fP) const

Find last occurence of a substring in our string.

Returns:

index of last instance found,

Parameters:

s string to search for.

offset offset to start from.

size_t ost::String::rfind (const char *s, size_toffset = \fC0\fP, size_tlen = \fC0\fP) const

Find last occurence of a text in our string.

Returns:

index of last instance found,

Parameters:

s string to search for.

offset offset to start from.

len size of string to look for.

size_t ost::String::search (const char *text, size_tclen = \fC0\fP, size_toffset = \fC0\fP) const\fC [protected]\fP

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:

text text to search for.

clen length of search text.

offset offset to start from.

const char* ost::String::set (const char *str, size_tlen = \fC0\fP)\fC [protected]\fP

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:

str string to set.

len length of string if passed.

void ost::String::set (const \fBString\fP &str)\fC [protected]\fP

Set the content of the string variable to that of another variable. Uses the string set method.

Parameters:

str string to copy from.

const char* ost::String::set (size_tsize, const char *format, ...)\fC [protected]\fP

Set the content of the string variable to that of a formatted printf style string.

Parameters:

size of string data to set.

format of string to write into object.

void ost::String::setLength (size_tlen)\fC [protected]\fP

Set the length value of the string content.

Parameters:

len size in bytes.

size_t ost::String::setSize (size_tsize)\fC [protected]\fP

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:

size in bytes.

size_t ost::String::size (void) const\fC [inline]\fP

Get actual length of string data.

Returns:

actual size of string.

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

Strip lead and trailing characters from a string.

Parameters:

cs list of chars to strip.

\fBString\fP ost::String::substr (size_tstart, size_tlen) const\fC [inline]\fP

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

Returns:

new string.

Parameters:

start starting offset for extracted substring.

len length of substring.

char* ost::String::text (void) const\fC [inline]\fP

Alternate get text method.

Returns:

string data.

\fBString\fP ost::String::token (const char *delim = \fC' \t\n\r'\fP, size_toffset = \fC0\fP)

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

Returns:

string containing token.

Parameters:

delim deliminator characters.

offset offset to start from.

void ost::String::trim (const char *cs)\fC [inline]\fP

Trim trailing characters from a string.

Parameters:

cs list of chars to trim.

References ost::strtrim().

void ost::String::trim (size_tcount)

Trim n trailing characters from a string.

Parameters:

count number of bytes to trim.

Friends And Related Function Documentation

\fB__EXPORT\fP std::istream& getline (std::istream &is, \fBString\fP &str, chardelim = \fC'\n'\fP, size_tsize = \fC0\fP)\fC [friend]\fP

Fetch input from a std::istream into the current string variable until either the string variable is filled (based on current length) or the deliminator is read.

Parameters:

is stream to read.

str string to save into.

delim deliminator to use.

size optional size limitor.

friend class \fBMemPager\fP\fC [friend]\fP

\fB__EXPORT\fP \fBString\fP operator+ (const \fBString\fP &s1, const \fBString\fP &s2)\fC [friend]\fP

Add two strings and return a temporary object.

\fB__EXPORT\fP \fBString\fP operator+ (const \fBString\fP &s1, const char *s2)\fC [friend]\fP

\fB__EXPORT\fP \fBString\fP operator+ (const char *s1, const \fBString\fP &s2)\fC [friend]\fP

\fB__EXPORT\fP \fBString\fP operator+ (const \fBString\fP &s1, const charc2)\fC [friend]\fP

\fB__EXPORT\fP \fBString\fP operator+ (const charc1, const \fBString\fP &s2)\fC [friend]\fP

\fB__EXPORT\fP std::ostream& operator<< (std::ostream &os, const \fBString\fP &str)\fC [friend]\fP

Stream the content of our string variable directly to a C++ streaming source.

std::istream& operator>> (std::istream &is, \fBString\fP &str)\fC [friend]\fP

Stream input into our variable.

friend class \fBStringObject\fP\fC [friend]\fP

\fB__EXPORT\fP int strprintf (\fBString\fP &str, size_tsize, const char *format, ...)\fC [friend]\fP

Print values directly into a string variable.

Returns:

character count.

Parameters:

str object reference to use.

size of string required.

format of data.

Member Data Documentation

bool ost::String::big

struct { ... } ost::String::bigstring

size_t ost::String::length

char ost::String::length

struct { ... } ost::String::ministring

const unsigned ost::String::minsize\fC [static]\fP, \fC [protected]\fP

const size_t ost::String::npos\fC [static]\fP

const unsigned ost::String::pagesize\fC [static]\fP, \fC [protected]\fP

size_t ost::String::size

const unsigned ost::String::slotcount\fC [static]\fP, \fC [protected]\fP

const unsigned ost::String::slotlimit\fC [static]\fP, \fC [protected]\fP

const unsigned ost::String::slotsize\fC [static]\fP, \fC [protected]\fP

char* ost::String::text

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

Author

Generated automatically by Doxygen for GNU CommonC++ from the source code.