CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

csString Class Reference

This is a string class with a range of useful operators and typesafe overloads. More...

#include <csstring.h>

List of all members.

Public Methods

void SetCapacity (size_t NewSize)
 Advise the string that it should allocate enough space to hold up to NewSize characters. More...

size_t GetCapacity () const
 Return the current capacity. More...

void SetGrowsBy (size_t)
 Advise the string that it should grow by approximately this many bytes when more space is required. More...

size_t GetGrowsBy () const
 Return the number of bytes by which the string grows. More...

void SetGrowsExponentially (bool b)
 Tell the string to re-size its buffer exponentially as needed. More...

bool GetGrowsExponentially () const
 Returns true if exponential growth is enabled. More...

void Free ()
 Free the memory allocated for the string. More...

csString & Truncate (size_t iLen)
 Truncate the string to length iLen. More...

csString & Reclaim ()
 Set string buffer capacity to exactly hold the current content. More...

csString & Clear ()
 Clear the string (so that it contains only a null terminator). More...

char * GetData () const
 Get a pointer to ASCIIZ string - warning: this is a non constpointer ,so use this function with care! More...

size_t Length () const
 Query string length. Length does not include null terminator. More...

bool IsEmpty () const
 Check if string is empty. More...

char & operator[] (size_t n)
 Get a reference to n'th character. More...

char operator[] (size_t n) const
 get n'th character. More...

void SetAt (size_t n, const char c)
 Set character at position `n'. More...

char GetAt (size_t n) const
 Get character at n'th position. More...

csString & DeleteAt (size_t iPos, size_t iCount=1)
 Delete iCount characters at starting iPos. More...

csString & Insert (size_t iPos, const csString &)
 Insert another string into this one at position iPos. More...

csString & Insert (size_t iPos, const char)
 Insert a char into this string at position iPos. More...

csString & Overwrite (size_t iPos, const csString &)
 Overlay another string onto a part of this string. More...

csString & Append (const char *, size_t iCount=(size_t)-1)
 Append an ASCIIZ string to this one. More...

csString & Append (const csString &iStr, size_t iCount=(size_t)-1)
 Append a string to this one. More...

csString & Append (char c)
 Append a character to this string. More...

csString & Append (unsigned char c)
 Append an unsigned character to this string. More...

csString & Append (bool b)
 Append a boolean (as a number -- 1 or 0) to this string. More...

csString & Replace (const csString &iStr, size_t iCount=(size_t)-1)
 Replace contents of this string with the contents of another. More...

csString & Replace (const char *iStr, size_t iCount=(size_t)-1)
 Replace contents of this string with the contents of another. More...

bool Compare (const csString &iStr) const
 Check if two strings are equal. More...

bool Compare (const char *iStr) const
 Check if an ASCIIZ string is equal to this string. More...

bool CompareNoCase (const csString &iStr) const
 Compare two strings ignoring case. More...

bool CompareNoCase (const char *iStr) const
 Compare ignoring case with an ASCIIZ string. More...

 csString ()
 Create an empty csString object. More...

 csString (size_t iLength)
 Create an csString object and reserve space for iLength characters. More...

 csString (const csString &copy)
 Copy constructor from existing csString. More...

 csString (const char *copy)
 Copy constructor from ASCIIZ string. More...

 csString (char c)
 Copy constructor from a character. More...

 csString (unsigned char c)
 Copy constructor from a character (unsigned). More...

virtual ~csString ()
 Destroy a csString object. More...

csString Clone () const
 Get a copy of this string. More...

csString & LTrim ()
 Trim leading whitespace. More...

csString & RTrim ()
 Trim trailing whitespace. More...

csString & Trim ()
 Trim leading and trailing whitespace. More...

csString & Collapse ()
 Trims leading and trailing whitespace, and collapses all internal whitespace to a single space. More...

csString & Format (const char *format,...)
 Format this string using sprintf() formatting directives. More...

csString & FormatV (const char *format, va_list args)
 Format this string using sprintf() formatting directives in a va_list. More...

csString & PadLeft (size_t iNewSize, char iChar='')
 Pad to specified size with leading characters (default: space). More...

csString AsPadLeft (size_t iNewSize, char iChar='')
 Return a new string formatted with PadLeft(). More...

csString & PadRight (size_t iNewSize, char iChar='')
 Pad to specified size with trailing characters (default: space). More...

csString AsPadRight (size_t iNewSize, char iChar='')
 Return a new string formatted with PadRight(). More...

csString & PadCenter (size_t iNewSize, char iChar='')
 Pad to specified size between characters (any remainder is appended). More...

csString AsPadCenter (size_t iNewSize, char iChar='')
 Return a copy of this string formatted with PadCenter(). More...

const csString & operator+ (const csString &iStr) const
 Add another string to this one and return the result as a new string. More...

 operator const char * () const
 Return a const reference to this string in ASCIIZ format. More...

bool operator== (const csString &iStr) const
 Check if two strings are equal. More...

char * Detach ()
 Detach the low-level null-terminated string buffer from the csString object. More...


Detailed Description

This is a string class with a range of useful operators and typesafe overloads.

Definition at line 30 of file csstring.h.


Constructor & Destructor Documentation

csString::csString   [inline]
 

Create an empty csString object.

Definition at line 273 of file csstring.h.

Referenced by Clone.

csString::csString size_t    iLength [inline]
 

Create an csString object and reserve space for iLength characters.

Definition at line 277 of file csstring.h.

References SetCapacity.

csString::csString const csString &    copy [inline]
 

Copy constructor from existing csString.

Definition at line 282 of file csstring.h.

References Append.

csString::csString const char *    copy [inline]
 

Copy constructor from ASCIIZ string.

Definition at line 287 of file csstring.h.

References Append.

csString::csString char    c [inline]
 

Copy constructor from a character.

Definition at line 292 of file csstring.h.

References Append.

csString::csString unsigned char    c [inline]
 

Copy constructor from a character (unsigned).

Definition at line 297 of file csstring.h.

References Append.

virtual csString::~csString   [virtual]
 

Destroy a csString object.


Member Function Documentation

csString& csString::Append bool    b [inline]
 

Append a boolean (as a number -- 1 or 0) to this string.

Definition at line 196 of file csstring.h.

References Append.

csString& csString::Append unsigned char    c [inline]
 

Append an unsigned character to this string.

Definition at line 179 of file csstring.h.

References Append.

csString& csString::Append char    c [inline]
 

Append a character to this string.

Definition at line 176 of file csstring.h.

References Append.

csString& csString::Append const csString &    iStr,
size_t    iCount = (size_t)-1
 

Append a string to this one.

If iCount is -1, then the entire string is appended. Otherwise, only iCount characters from the string are appended.

csString& csString::Append const char *   ,
size_t    iCount = (size_t)-1
 

Append an ASCIIZ string to this one.

If iCount is -1, then the entire string is appended. Otherwise, only iCount characters from the string are appended.

Referenced by Append, csString, operator+, and Replace.

csString csString::AsPadCenter size_t    iNewSize,
char    iChar = ''
 

Return a copy of this string formatted with PadCenter().

csString csString::AsPadLeft size_t    iNewSize,
char    iChar = ''
 

Return a new string formatted with PadLeft().

csString csString::AsPadRight size_t    iNewSize,
char    iChar = ''
 

Return a new string formatted with PadRight().

csString& csString::Clear   [inline]
 

Clear the string (so that it contains only a null terminator).

Definition at line 101 of file csstring.h.

References Truncate.

csString csString::Clone   const [inline]
 

Get a copy of this string.

Definition at line 305 of file csstring.h.

References csString.

Referenced by operator+.

csString& csString::Collapse  
 

Trims leading and trailing whitespace, and collapses all internal whitespace to a single space.

bool csString::Compare const char *    iStr const [inline]
 

Check if an ASCIIZ string is equal to this string.

Definition at line 252 of file csstring.h.

bool csString::Compare const csString &    iStr const [inline]
 

Check if two strings are equal.

Definition at line 239 of file csstring.h.

References GetData, and Length.

Referenced by operator==.

bool csString::CompareNoCase const char *    iStr const [inline]
 

Compare ignoring case with an ASCIIZ string.

Definition at line 269 of file csstring.h.

bool csString::CompareNoCase const csString &    iStr const [inline]
 

Compare two strings ignoring case.

Definition at line 256 of file csstring.h.

References GetData, and Length.

csString& csString::DeleteAt size_t    iPos,
size_t    iCount = 1
 

Delete iCount characters at starting iPos.

char* csString::Detach   [inline]
 

Detach the low-level null-terminated string buffer from the csString object.

The caller of this function becomes the owner of the returned string buffer and is responsible for destroying it via `delete[]' when no longer needed. The returned value may be NULL if no buffer had been allocated for this string.

Definition at line 507 of file csstring.h.

csString& csString::Format const char *    format,
...   
 

Format this string using sprintf() formatting directives.

Automatically allocates sufficient memory to hold result. Newly formatted string overwrites previous string value.

csString& csString::FormatV const char *    format,
va_list    args
 

Format this string using sprintf() formatting directives in a va_list.

Automatically allocates sufficient memory to hold result. Newly formatted string overwrites previous string value.

void csString::Free  
 

Free the memory allocated for the string.

char csString::GetAt size_t    n const [inline]
 

Get character at n'th position.

Definition at line 144 of file csstring.h.

size_t csString::GetCapacity   const [inline]
 

Return the current capacity.

Definition at line 64 of file csstring.h.

char* csString::GetData   const [inline]
 

Get a pointer to ASCIIZ string - warning: this is a non constpointer ,so use this function with care!

Definition at line 108 of file csstring.h.

Referenced by Compare, and CompareNoCase.

size_t csString::GetGrowsBy   const [inline]
 

Return the number of bytes by which the string grows.

Definition at line 77 of file csstring.h.

bool csString::GetGrowsExponentially   const [inline]
 

Returns true if exponential growth is enabled.

Definition at line 88 of file csstring.h.

csString& csString::Insert size_t    iPos,
const    char
 

Insert a char into this string at position iPos.

csString& csString::Insert size_t    iPos,
const csString &   
 

Insert another string into this one at position iPos.

bool csString::IsEmpty   const [inline]
 

Check if string is empty.

Definition at line 116 of file csstring.h.

size_t csString::Length   const [inline]
 

Query string length. Length does not include null terminator.

Definition at line 112 of file csstring.h.

Referenced by Compare, and CompareNoCase.

csString& csString::LTrim  
 

Trim leading whitespace.

csString::operator const char *   const [inline]
 

Return a const reference to this string in ASCIIZ format.

Definition at line 487 of file csstring.h.

const csString& csString::operator+ const csString &    iStr const [inline]
 

Add another string to this one and return the result as a new string.

Definition at line 483 of file csstring.h.

References Append, and Clone.

bool csString::operator== const csString &    iStr const [inline]
 

Check if two strings are equal.

Definition at line 491 of file csstring.h.

References Compare.

char csString::operator[] size_t    n const [inline]
 

get n'th character.

Definition at line 127 of file csstring.h.

char& csString::operator[] size_t    n [inline]
 

Get a reference to n'th character.

Definition at line 120 of file csstring.h.

csString& csString::Overwrite size_t    iPos,
const csString &   
 

Overlay another string onto a part of this string.

csString& csString::PadCenter size_t    iNewSize,
char    iChar = ''
 

Pad to specified size between characters (any remainder is appended).

csString& csString::PadLeft size_t    iNewSize,
char    iChar = ''
 

Pad to specified size with leading characters (default: space).

csString& csString::PadRight size_t    iNewSize,
char    iChar = ''
 

Pad to specified size with trailing characters (default: space).

csString& csString::Reclaim  
 

Set string buffer capacity to exactly hold the current content.

csString& csString::Replace const char *    iStr,
size_t    iCount = (size_t)-1
[inline]
 

Replace contents of this string with the contents of another.

If iCount is -1, then use the entire replacement string. Otherwise, use iCount characters from the replacement string.

Definition at line 215 of file csstring.h.

References Append.

csString& csString::Replace const csString &    iStr,
size_t    iCount = (size_t)-1
[inline]
 

Replace contents of this string with the contents of another.

If iCount is -1, then use the entire replacement string. Otherwise, use iCount characters from the replacement string.

Definition at line 204 of file csstring.h.

References Append.

csString& csString::RTrim  
 

Trim trailing whitespace.

void csString::SetAt size_t    n,
const char    c
[inline]
 

Set character at position `n'.

Does not expand string if `n' is greater than length of string.

Definition at line 137 of file csstring.h.

void csString::SetCapacity size_t    NewSize
 

Advise the string that it should allocate enough space to hold up to NewSize characters.

After calling this method, the string's capacity will be at least NewSize + 1 (one for the implicit null terminator). Never shrinks capacity. If you need to actually reclaim memory, then use Free() or Reclaim().

Referenced by csString.

void csString::SetGrowsBy size_t   
 

Advise the string that it should grow by approximately this many bytes when more space is required.

This value is only a suggestion. The actual value by which it grows may be rounded up or down to an implementation-dependent allocation multiple. This method turns off exponential growth.

void csString::SetGrowsExponentially bool    b [inline]
 

Tell the string to re-size its buffer exponentially as needed.

If set to true, the GetGrowsBy() setting is ignored.

Definition at line 84 of file csstring.h.

csString& csString::Trim  
 

Trim leading and trailing whitespace.

csString& csString::Truncate size_t    iLen
 

Truncate the string to length iLen.

Referenced by Clear.


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.14