Main Page   Class Hierarchy   Compound List   File List   Compound Members  

TString Class Reference

String class featuring unique strings. More...

#include <TString.hh>

List of all members.

Public Methods

 TString ()
 Constructs a string of length zero.

 TString (const char *cs)
 Constructs a string from the null terminated string cs.

 TString (const char *cs, int n)
 Constructs a string from the string cs of length n.

 TString (const TString &str)
 Constructs a string from str.

 TString (char c)
 Constructs a string containing the single character c.

 TString (char c, int n)
 Constructs a string containing the character c repeated n times.

 ~TString ()
 Destructor.

 operator const char * () const
 Return internal data as a null terminated character string.

 operator int () const
 Convert the string to an integer.

 operator unsigned int () const
 Convert the string to an unsigned integer.

TString & operator= (const char *cs)
 Copy the null terminated string cs.

TString & operator= (const TString &str)
 Copy the data of string str.

bool operator== (const TString &str) const
 Compare string for equality with other TString object.

bool operator== (const char *cs) const
 Compare string for equality with character string.

bool operator!= (const TString &str)
 Compares two string objects for non-equality.

TString & operator+= (const char *cs)
 Append cs to string.

TString & operator+= (const TString &str)
 Append str to string.

TString & operator+= (char c)
 Append the character c to string.

TString operator+ (const char *cs)
 Append two strings together creating a third.

TString operator+ (const TString &str)
 Append two strings together creating a third.

char operator[] (int i) const
 Index operator.

TString & Append (char c)
 Append the character c.

TString & Append (char c, int n)
 Append n copies of the character c.

TString & Append (const char *cs)
 Append a copy of the null terminated string cs.

TString & Append (const char *cs, int n)
 Append a copy of the first n bytes of cs.

TString & Append (const TString &str)
 Append a copy of str to string.

TString BaseName () const
 Return a string containing the basename of the string.

TString DirName () const
 Return a string containing the dirname of the string.

const char * Data () const
 Return the data of ths string as a null terminated character string.

TString & Clear ()
 Clear string.

bool Empty () const
 Check if the string is empty.

TString & Format (const char *fmt,...)
 Format a string as printf does.

TString & Insert (int pos, char c)
 Insert the character c at position pos.

TString & Insert (int pos, char c, int n)
 Insert n copies of the character c at position pos.

TString & Insert (int pos, const char *cs)
 Insert a copy of the null terminated string cs at position pos.

TString & Insert (int pos, const char *cs, int n)
 Insert a copy of the first n bytes of cs at position pos.

TString & Insert (int pos, const TString &str)
 Insert a copy of str at position pos.

unsigned int Hash () const
 Calculate hash value of string.

bool IsAscii () const
 Check is the string conists of ASCII characters only.

bool IsDigits () const
 Check if the string conists of decimal digits only.

bool IsXDigits () const
 Check if the string conists of hexa decimal digits only.

int Length () const
 Returns the length of the string.

int Integer () const
 Convert the string to an integer.

TString & Lower ()
 Convert string to lowercase letters only.

TString & Prepend (char c)
 Prepend the character c.

TString & Prepend (char c, int n)
 Prepend n copies of the character c.

TString & Prepend (const char *cs)
 Prepend a copy of the null terminated string cs.

TString & Prepend (const char *cs, int n)
 Prepend a copy of the first n bytes of cs.

TString & Prepend (const TString &str)
 Prepend a copy of str.

void Print (bool newline=true) const
 Print string to stdout.

TString & Trim ()
 Trim whitespace from beginning and end of string.

TString & TrimLeft ()
 Trim whitespace from beginning of string.

TString & TrimRight ()
 Trim whitespace from end of string.

TString & Truncate (int pos)
 Truncate string at the specified position.

unsigned int UnsignedInteger () const
 Convert the string to an unsigned integer.

TString & Upper ()
 Convert string to uppercase letters only.


Static Public Methods

int Length (const char *cs)
 Faster than strlen() for short strings and according to my tests equal on long strings.

void PrintStatus ()
 Print status from mapping.


Detailed Description

String class featuring unique strings.

String compares are extremely fast, modifications on the other hand are slow, append is a special case wich is optimised.

Author:
Johan Bolmsjo <johan@nocrew.org>


Member Function Documentation

TString TString::BaseName   const
 

Return a string containing the basename of the string.

See the Unix man page for basename.

const char* TString::Data   const [inline]
 

Return the data of ths string as a null terminated character string.

The data may not be modified and the pointer will not be vaild once the string goes out of scope.

TString TString::DirName   const
 

Return a string containing the dirname of the string.

See the Unix man page for dirname.

bool TString::Empty   const [inline]
 

Check if the string is empty.

Returns:
true, empty or false populated

TString& TString::Format const char *    fmt,
...   
 

Format a string as printf does.

For now only the convertion codes d, u and s are supported (without additional formating).

Parameters:
fmt Format string, for example "Celivin is d years old."
... Aditional arguments

unsigned int TString::Hash   const [inline]
 

Calculate hash value of string.

Returns:
Hash value

int TString::Integer   const
 

Convert the string to an integer.

Valid characters are 0 to 9 and at the first position the '-' character is also allowed. If an invalid character is found, what has been converted so far is returned. For example the string 42e3 would return an integer with the value of 42. There is no overflow check.

Returns:
Integer representation of string.

bool TString::IsAscii   const
 

Check is the string conists of ASCII characters only.

That is bit 7 is cleared for all characters.

Returns:
true, ASCII only or false, non ASCII

bool TString::IsDigits   const
 

Check if the string conists of decimal digits only.

Returns:
true, false

bool TString::IsXDigits   const
 

Check if the string conists of hexa decimal digits only.

Returns:
true, false

int TString::Length const char *    cs [inline, static]
 

Faster than strlen() for short strings and according to my tests equal on long strings.

Parameters:
cs Null terminated C string.
Returns:
Length of string.

TString::operator const char *   const [inline]
 

Return internal data as a null terminated character string.

The data may not be modified and the pointer will not be vaild once the string goes out of scope.

bool TString::operator!= const TString &    str [inline]
 

Compares two string objects for non-equality.

This is a matter of comparing two pointers and is very fast!

bool TString::operator== const TString &    str const [inline]
 

Compare string for equality with other TString object.

This is a matter of comparing two pointers and is very fast!

char TString::operator[] int    i const [inline]
 

Index operator.

Provides read-only access only.

void TString::Print bool    newline = true const
 

Print string to stdout.

newline specifies if a newline should be printed after the string.

void TString::PrintStatus   [inline, static]
 

Print status from mapping.

Used to debug things.

unsigned int TString::UnsignedInteger   const
 

Convert the string to an unsigned integer.

Valid characters are 0 to 9. If an invalid character is found, what has been converted so far is returned. For example the string 42e3 would return an integer with the value of 42. There is no overflow check.

Returns:
Unsigned integer representation of string.


The documentation for this class was generated from the following file:
Generated on Sat Feb 15 18:37:16 2003 for Tools by doxygen1.3-rc2