Class Hierarchy   Class Index   Method Index  

CHMstring Class Reference

#include <CHMstring.h>


Detailed Description

Custom string class.

Because Chameleon is cross platform is it necessary to use a string class which is independent of the various compilers, operating systems, and C++ class libraries we support. This string is efficiently implemented with reference counting.


Public Types

enum  StripType { Leading, Trailing, Both }
 Used as an argument for the strip function to specify its behavior. More...

Public Member Functions

 CHMstring (void)
 Construct an empty string.
 CHMstring (const CHMstring &s)
 Copy constructor.
 CHMstring (const CHMstring &s, const size_t &orig, const size_t &n=npos)
 Construct a string from a substring of the string s starting at index orig for n characters.
 CHMstring (const CHMchar *cp)
 Construct a string from a null terminated string cp.
 CHMstring (const CHMchar *cp, const size_t &orig, const size_t &n=npos)
 Construct a string from a substring of a null terminated string cp starting at index orig for n characters.
 CHMstring (CHMchar c)
 Construct a string from the character c.
 CHMstring (size_t n, CHMchar c)
 Construct a string that consists of n characters of type c.
 ~CHMstring (void)
 Destructor.
CHMstringoperator= (const CHMstring &s)
 Assignment operator.
CHMstringoperator+= (const CHMchar *cp)
 Concatenation operator for adding a null terminated string to this string.
CHMstringoperator+= (const CHMstring &s)
 Concatenation operator for adding another string to this string.
const CHMchar operator[] (const size_t &pos) const
 Const operator [pos] returns the character at index pos in this string.
CHMchar & operator[] (const size_t &pos)
 Non-const operator [pos] returns the character at index pos in this string.
CHMstringappend (const CHMchar *cp, const size_t &orig=0, const size_t &n=npos)
 Append the null terminated string cp of size n to this string at index orig.
CHMstringappend (size_t SizeOfBuffer, const CHMchar *Buffer)
 Append the first SizeOfBuffer characters from Buffer to this string.
CHMstringappend (const CHMstring &s, const size_t &orig=0, const size_t &n=npos)
 Append string s of size n to this string at index orig.
void assign (size_t n, CHMchar Filler)
 Change this string to consist of an array of n characters of type Filler.
const CHMchar * c_str (void) const
 Get a const CHMchar pointer to the buffer of this string object.
void clear (void)
 Clear this string.
int compare (const CHMchar *Compare) const
 Compare this string for equality to the null terminated string Compare.
int compare (const CHMstring &s) const
 Compare this string for equality to another string s.
const size_t find (const CHMstring &s, const size_t &pos=0) const
 Find the first instance of string s from index pos in this string.
CHMchar * get_buffer (void)
 Get a non-const CHMchar pointer to the buffer of this string.
CHMstringinsert (size_t pos, const CHMchar *cp, const size_t &orig=0, const size_t &n=npos)
 Insert the null terminated string cp of length n starting at index orig into this string at index pos.
CHMstringinsert (size_t pos, const CHMstring &s, const size_t &orig=0, const size_t &n=npos)
 Insert the string s of length n starting at index orig into this string at index pos.
const CHMboolean is_null (void) const
 Check if this string is empty.
CHMstringprepend (const CHMchar *cp, const size_t &orig=0, const size_t &n=npos)
 Prepend the null terminated string cp of size n to this string at index orig.
CHMstringprepend (const CHMstring &s, const size_t &orig=0, const size_t &n=npos)
 Prepend the string s of size n to this string at index orig.
CHMstringremove (const size_t &pos, const size_t &n=npos)
 Remove the substring starting at index pos of length n from this string.
CHMstringreplace (const size_t &pos, const size_t &n1, const CHMstring &s, const size_t &orig=0, const size_t &n2=npos)
 Replace the substring of size n1 starting at index pos with string s of size n2 starting at index orig.
const size_t rfind (const CHMstring &s, const size_t &pos) const
 Find the first instance of string s searching backwards through this string from index pos.
const size_t rfind (const CHMstring &s) const
 Find the first instance of string s searching backwards through this string.
const size_t & size (void) const
 Get the length of this string.
CHMstring strip (const StripType &s=Trailing, const CHMchar &c= ' ') const
 Strip char c from the beginning or the end or from both ends of this string depending on the value of the enumerator StripType.
void stripAll (const CHMchar &c= ' ')
 Strip all copies of char c from this string.
void subChar (const CHMchar pTarget, const CHMchar pReplacement)
 Substitute characters of type pTarget with those of pReplacement.
CHMstring substr (const size_t &pos, const size_t &n=npos) const
 Get the substring at index pos of n characters in length or until the end of the original string has been reached.


Member Enumeration Documentation

enum CHMstring::StripType
 

Used as an argument for the strip function to specify its behavior.

Enumerator:
Leading  Strip leading characters only.
Trailing  Strip trailing characters only.
Both  Strip both leading and trailing characters.


Constructor & Destructor Documentation

CHMstring::CHMstring void   )  [inline]
 

Construct an empty string.

CHMstring::CHMstring const CHMstring s  ) 
 

Copy constructor.

CHMstring::CHMstring const CHMstring s,
const size_t &  orig,
const size_t &  n = npos
 

Construct a string from a substring of the string s starting at index orig for n characters.

npos = (size_t) - 1 .

CHMstring::CHMstring const CHMchar *  cp  ) 
 

Construct a string from a null terminated string cp.

CHMstring::CHMstring const CHMchar *  cp,
const size_t &  orig,
const size_t &  n = npos
 

Construct a string from a substring of a null terminated string cp starting at index orig for n characters.

npos = (size_t) - 1 .

CHMstring::CHMstring CHMchar  c  ) 
 

Construct a string from the character c.

CHMstring::CHMstring size_t  n,
CHMchar  c
 

Construct a string that consists of n characters of type c.

CHMstring::~CHMstring void   ) 
 

Destructor.


Member Function Documentation

CHMstring & CHMstring::append const CHMstring s,
const size_t &  orig = 0,
const size_t &  n = npos
[inline]
 

Append string s of size n to this string at index orig.

Returns the resulting string.

CHMstring& CHMstring::append size_t  SizeOfBuffer,
const CHMchar *  Buffer
 

Append the first SizeOfBuffer characters from Buffer to this string.

Buffer is not necessarily null terminated. Returns the resulting string.

CHMstring& CHMstring::append const CHMchar *  cp,
const size_t &  orig = 0,
const size_t &  n = npos
 

Append the null terminated string cp of size n to this string at index orig.

Returns the resulting string.

void CHMstring::assign size_t  n,
CHMchar  Filler
 

Change this string to consist of an array of n characters of type Filler.

const CHMchar * CHMstring::c_str void   )  const [inline]
 

Get a const CHMchar pointer to the buffer of this string object.

The caller is not allowed to write to this buffer since other string objects may be referencing it.

void CHMstring::clear void   ) 
 

Clear this string.

int CHMstring::compare const CHMstring s  )  const
 

Compare this string for equality to another string s.

This method invokes the standard C strcmp function. It returns 0 if the strings are equal.

int CHMstring::compare const CHMchar *  Compare  )  const
 

Compare this string for equality to the null terminated string Compare.

This method invokes the standard C strcmp function. It returns 0 if the strings are equal.

const size_t CHMstring::find const CHMstring s,
const size_t &  pos = 0
const
 

Find the first instance of string s from index pos in this string.

Returns the index of the string if found; otherwise, returns npos = (size_t)-1 .

CHMchar* CHMstring::get_buffer void   ) 
 

Get a non-const CHMchar pointer to the buffer of this string.

The caller is allowed to write to the buffer since this call ensures that no other strings reference the buffer.

CHMstring & CHMstring::insert size_t  pos,
const CHMstring s,
const size_t &  orig = 0,
const size_t &  n = npos
[inline]
 

Insert the string s of length n starting at index orig into this string at index pos.

Returns the resulting string.

CHMstring& CHMstring::insert size_t  pos,
const CHMchar *  cp,
const size_t &  orig = 0,
const size_t &  n = npos
 

Insert the null terminated string cp of length n starting at index orig into this string at index pos.

Returns the resulting string.

const CHMboolean CHMstring::is_null void   )  const [inline]
 

Check if this string is empty.

CHMstring& CHMstring::operator+= const CHMstring s  ) 
 

Concatenation operator for adding another string to this string.

CHMstring& CHMstring::operator+= const CHMchar *  cp  ) 
 

Concatenation operator for adding a null terminated string to this string.

CHMstring& CHMstring::operator= const CHMstring s  ) 
 

Assignment operator.

CHMchar& CHMstring::operator[] const size_t &  pos  ) 
 

Non-const operator [pos] returns the character at index pos in this string.

const CHMchar CHMstring::operator[] const size_t &  pos  )  const [inline]
 

Const operator [pos] returns the character at index pos in this string.

CHMstring & CHMstring::prepend const CHMstring s,
const size_t &  orig = 0,
const size_t &  n = npos
[inline]
 

Prepend the string s of size n to this string at index orig.

Returns the resulting string.

CHMstring& CHMstring::prepend const CHMchar *  cp,
const size_t &  orig = 0,
const size_t &  n = npos
 

Prepend the null terminated string cp of size n to this string at index orig.

Returns the resulting string.

CHMstring& CHMstring::remove const size_t &  pos,
const size_t &  n = npos
 

Remove the substring starting at index pos of length n from this string.

Returns the resulting string.

CHMstring& CHMstring::replace const size_t &  pos,
const size_t &  n1,
const CHMstring s,
const size_t &  orig = 0,
const size_t &  n2 = npos
 

Replace the substring of size n1 starting at index pos with string s of size n2 starting at index orig.

const size_t CHMstring::rfind const CHMstring s  )  const [inline]
 

Find the first instance of string s searching backwards through this string.

Returns the index of the string if found; otherwise, returns npos = (size_t)-1 .

const size_t CHMstring::rfind const CHMstring s,
const size_t &  pos
const
 

Find the first instance of string s searching backwards through this string from index pos.

Returns the index of the string if found; otherwise, returns npos = (size_t)-1 .

const size_t& CHMstring::size void   )  const
 

Get the length of this string.

CHMstring CHMstring::strip const StripType s = Trailing,
const CHMchar &  c = ' '
const
 

Strip char c from the beginning or the end or from both ends of this string depending on the value of the enumerator StripType.

Returns the resulting string.

void CHMstring::stripAll const CHMchar &  c = ' '  ) 
 

Strip all copies of char c from this string.

void CHMstring::subChar const CHMchar  pTarget,
const CHMchar  pReplacement
 

Substitute characters of type pTarget with those of pReplacement.

CHMstring CHMstring::substr const size_t &  pos,
const size_t &  n = npos
const
 

Get the substring at index pos of n characters in length or until the end of the original string has been reached.


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