tString Class Reference

string class: standard string with some extras More...

#include <tString.h>

Inheritance diagram for tString:

Inheritance graph
[legend]

List of all members.

Public Types

typedef tString THISCLASS
 typedef for this class
typedef std::string BASE
 typedef for base clase
typedef BASE::value_type CHAR
 the character class

Public Member Functions

 tString ()
 default constructor
 tString (const BASE &)
 pseudo copy constructor
 tString (const tString &)
 copy constructor
 tString (const CHAR *)
 conversion from C string
template<typename T>
 tString (T begin, T end)
 initialisation by iterators
 WRAP_OPERATOR_ALLTYPES (+) WRAP_MUTATING_OPERATOR_ALLTYPES(+
 assignment from output collector
size_type Size () const
 Returns the size of the string in characters.
template<class T>
bool Convert (T &target, size_type startPos=0) const
 Converts the string to an arbitrary type, starting at the given position.
void ReadLine (std::istream &s, bool enableEscapeSequences=false)
 read a whole line from a stream into this string
void Clear ()
 clears the string
void SetPos (int len, bool cut)
 makes this string exactly of length len.
bool StartsWith (const tString &other) const
 determines whether this string starts with the argument string
bool StartsWith (const CHAR *other) const
 determines whether this string starts with the argument string
bool EndsWith (const tString &other) const
 determines whether this string ends with the argument string
bool EndsWith (const CHAR *other) const
 determines whether this string ends with the argument string
tString LTrim () const
 returns a copy with leading whitespace removed
tString RTrim () const
 returns a copy with trailing whitespace removed
tString Trim () const
 returns a copy with leading and trailing whitespace removed
int StrPos (const tString &tofind) const
 Get the position of a substring within this string.
int StrPos (int start, const tString &tofind) const
 Get the position of a substring within this string.
int StrPos (const CHAR *tofind) const
 Get the position of a substring within this string.
int StrPos (int start, const CHAR *tofind) const
 Get the position of a substring within this string.
tString SubStr (int start, int len) const
 Get an arbitrary substring within this string.
tString SubStr (int start) const
 Get a substring within this string from the end.
int ToInt (size_type pos=0) const
 Returns the string converted to an integer.
REAL ToFloat (size_type pos=0) const
 Returns the string converted to a float.
tString StripWhitespace (void) const
 Strips all whitespace from a string.
tString ToLower (void) const
 Converts the string to lowercase.
tString ToUpper (void) const
 Converts the string to uppercase.
int PosWordRight (int start) const
 Computes the position of the next delimiter relative to start.
int PosWordLeft (int start) const
 Computes the position of the previous delimiter relative to start.
int RemoveWordRight (int start)
 Remove word right according to the delimiters.
int RemoveWordLeft (int start)
 Remove word left according to the delimiters.
void RemoveSubStr (int start, int length)
 Remove a substring, in-place.
tString GetFileMimeExtension () const
 Gets the lowercased file extension, as in a MIME type.
tString Reverse () const
 Reverses strings.
tString Truncate (int truncateAt) const
 Returns a truncated string (copy of this with excess chars replaced by "...").
CHAR operator[] (size_t i) const
CHARoperator[] (size_t i)
CHAR operator[] (int i) const
CHARoperator[] (int i)
void SetSize (unsigned int size)
 sets the string length by cutting or appending spaces
CHAR operator() (size_t i) const
CHARoperator() (size_t i)
CHAR operator() (int i) const
CHARoperator() (int i)
int Compare (const CHAR *other) const
 Compares two strings lexicographically.
int Compare (const CHAR *other, bool ignoreCase) const
 Compares two strings lexicographically, ignoring case differences if second argument is true.
 operator const CHAR * () const
int Count (CHAR what) const
 Counts the number of a certain character within the string.
int LongestLine () const
 the length of the longest line
int Len () const
 returns the lenghth PLUS ONE (the allocated length)
void SetLen (int len)
 sets the allocated length
void NetFilter ()
 filters strings from the net for strange things like newlines

Static Public Member Functions

static int CompareAlphaNumerical (const tString &a, const tString &b)
 Compares two strings alphanumerically.


Detailed Description

string class: standard string with some extras

Definition at line 61 of file tString.h.


Member Typedef Documentation

typedef tString tString::THISCLASS

typedef for this class

Reimplemented in tColoredString.

Definition at line 64 of file tString.h.

typedef std::string tString::BASE

typedef for base clase

Reimplemented in tColoredString.

Definition at line 65 of file tString.h.

typedef BASE::value_type tString::CHAR

the character class

Definition at line 66 of file tString.h.


Constructor & Destructor Documentation

tString::tString ( void   ) 

default constructor

Definition at line 302 of file tString.cpp.

Referenced by GetFileMimeExtension(), and SubStr().

00303 {
00304 }

Here is the caller graph for this function:

tString::tString ( const BASE other  ) 

pseudo copy constructor

Parameters:
other source of copy operation

Definition at line 316 of file tString.cpp.

00317         : string( other )
00318 {
00319 }

tString::tString ( const tString other  ) 

copy constructor

Parameters:
other source of copy operation

Definition at line 331 of file tString.cpp.

00332         : string( other )
00333 {
00334 }

tString::tString ( const CHAR other  )  [explicit]

conversion from C string

Parameters:
other source of copy operation

Definition at line 346 of file tString.cpp.

00347         : string( other ? other : "" )
00348 {
00349     // tASSERT( other );
00350 }

template<typename T>
tString::tString ( begin,
end 
) [inline]

initialisation by iterators

Definition at line 73 of file tString.h.


Member Function Documentation

tString::WRAP_OPERATOR_ALLTYPES (  ) 

assignment from output collector

tString::size_type tString::Size ( void   )  const

Returns the size of the string in characters.

Returns:
the size of the string in characters NOT including the trailing 0.

Definition at line 395 of file tString.cpp.

Referenced by FilterLine(), ePlayerNetID::FilterName(), rTextField::FlushLine(), GetParent(), tLocaleItem::Load(), tConfItemBase::LoadAll(), nServerInfoBase::NetReadThis(), operator>>(), tConsole::Print(), RemoveTrailingColor(), se_StripMatchingEnds(), and ToT().

00396 {
00397     return size();
00398 }

Here is the caller graph for this function:

template<class T>
bool tString::Convert ( T &  target,
size_type  startPos = 0 
) const [inline]

Converts the string to an arbitrary type, starting at the given position.

Parameters:
target the variable to write the conversion result to
startPos the position to start the conversion at
Returns:
true on success

Definition at line 276 of file tString.h.

Referenced by cWidget::WithDataFunctions::ProcessDataSource(), and ToT().

00277 {
00278     // generate string stream and advance it to the start position
00279     std::istringstream s(*this);
00280     s.seekg(startPos);
00281 
00282     // read it
00283     s >> target;
00284 
00285     // return failure condition
00286     return !s.fail() && s.eof() || isspace(s.get());
00287 }

Here is the caller graph for this function:

void tString::ReadLine ( std::istream &  s,
bool  enableEscapeSequences = false 
)

read a whole line from a stream into this string

Parameters:
s stream to read from
enableEscapeSequences set to true if escape sequences (
) shall be respected

Definition at line 411 of file tString.cpp.

References c, Clear(), isblank(), and st_ReadEscapeSequence().

Referenced by tStatFile::flushWrites(), tTextFileRecorder::GetLine(), eVoter::HandleChat(), gAICharacter::Load(), tLocaleItem::Load(), nServerInfo::Load(), tConfItemBase::LoadAll(), tIniFile::LoadFile(), tConfItemBase::LoadLine(), tPlayList::LoadPlaylist(), nKrawall::nMethod::nMethod(), operator>>(), tStatFile::read(), tSettingRotation::ReadVal(), tConfItemLine::ReadVal(), nConfItemLine::ReadVal(), tConfItemPassword::ReadVal(), se_ChatMe(), se_ChatMsg(), se_ChatShuffle(), se_ChatTeam(), se_NeedsServer(), and st_Dummy().

00412 {
00413     char c=' ';
00414     Clear();
00415     while(c!='\n' && c!='\r' && isblank(c) &&  s.good() && !s.eof()){
00416         c=s.get();
00417     }
00418 
00419     s.putback(c);
00420     c='x';
00421 
00422     while( true )
00423     {
00424         c=s.get();
00425 
00426         // notice end of line or file
00427         if ( c=='\n' || c=='\r' || !s.good() || s.eof())
00428             break;
00429 
00430         if ( enableEscapeSequences )
00431         {
00432             char c2 = '\0';
00433             if ( st_ReadEscapeSequence( c, c2, s ) )
00434             {
00435                 *this += c;
00436                 c = 'x';
00437                 continue;
00438             }
00439             else if ( c2 )
00440             {
00441                 *this += c;
00442                 *this += c2;
00443                 c = 'x';
00444                 continue;
00445             }
00446         }
00447 
00448         *this += c;
00449     }
00450 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tString::Clear ( void   ) 

clears the string

Definition at line 461 of file tString.cpp.

Referenced by nServerInfo::DeleteAll(), eMenuItemKick::eMenuItemKick(), ePlayer::ePlayer(), nServerInfo::GetFromLAN(), nServerInfo::GetFromLANContinuously(), nAddress::GetHostname(), tLocale::Load(), tLocaleItem::Load(), tLanguage::Load(), lowlevel_sr_InitDisplay(), nServerInfo::NetReadThis(), tOutput::operator const char *(), tLocaleItem::operator const char *(), operator>>(), PasswordCallback(), ReadLine(), SetPos(), ePlayerNetID::UpdateName(), and rTextField::WriteChar().

00462 {
00463 #ifdef _MSC_VER
00464     *this = "";
00465 #else
00466     string::clear();
00467 #endif
00468 }

Here is the caller graph for this function:

void tString::SetPos ( int  l,
bool  cut 
)

makes this string exactly of length len.

Parameters:
len the target length
cut if set, the string may be cut back if its current length is bigger than length

Reimplemented in tColoredString.

Definition at line 481 of file tString.cpp.

References Clear(), Len(), and SetSize().

Referenced by tConfItemBase::DocAll(), tStatFile::flushWrites(), tConfItemBase::LoadLine(), nServerInfo::NetReadThis(), eTeam::Ranking(), ePlayerNetID::Ranking(), and tColoredString::SetPos().

00481                                    {
00482     int i;
00483     if ( l < Len() )
00484     {
00485         if ( cut )
00486         {
00487             if ( l > 0 )
00488             {
00489                 SetSize( l-1 );
00490                 operator+=(' ');
00491             }
00492             else
00493             {
00494                 Clear();
00495             }
00496         }
00497         else
00498         {
00499             operator+=(' ');
00500         }
00501     }
00502     for(i=Len();i<l;i++)
00503         operator+=(' ');
00504 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tString::StartsWith ( const tString other  )  const

determines whether this string starts with the argument string

Parameters:
other the string to compare the start with
Returns:
true if this starts with other

Definition at line 522 of file tString.cpp.

References Len().

Referenced by EndsWith(), ExtractConnectionInformation(), tConfItemBase::LoadAll(), tIniFile::LoadFile(), tPlayList::LoadPlaylist(), s_Veto(), tXmlParserNamespace::sg_IgnoreRequest(), and st_RelocatePath().

00523 {
00524     // const tString & rmhxt = *this;
00525     // rmhxt.RemoveHex();
00526     // *this = rmhxt;
00527     // other.RemoveHex();
00528     if (other.Len() > Len()) {
00529         return false;
00530     }
00531     for (int i=0; i<other.Len()-1; i++) {
00532         if (other[i] != (*this)[i]) {
00533             return false;
00534         }
00535     }
00536 
00537     return true;
00538 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tString::StartsWith ( const CHAR other  )  const

determines whether this string starts with the argument string

bool tString::EndsWith ( const tString other  )  const

determines whether this string ends with the argument string

Parameters:
other the string to compare the end with
Returns:
true if this ends with other

Definition at line 571 of file tString.cpp.

References Len(), Reverse(), and StartsWith().

Referenced by tXmlParserNamespace::sg_IgnoreRequest().

00572 {
00573     if (other.Len() > Len()) {
00574         return false;
00575     }
00576     tString thisString = Reverse();
00577     tString otherString(other);
00578     otherString = otherString.Reverse();
00579 
00580     // Haha, just use StartsWith to do the comparison :)
00581     return thisString.StartsWith(otherString);
00582     //return true;
00583 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tString::EndsWith ( const CHAR other  )  const

determines whether this string ends with the argument string

tString tString::LTrim ( void   )  const

returns a copy with leading whitespace removed

Returns:
the trimmed string

Definition at line 606 of file tString.cpp.

References isblank().

Referenced by RTrim(), and Trim().

00607 {
00608     tString toReturn;
00609     bool trim = true;
00610 
00611     for( size_t i = 0; i<size(); i++ )
00612     {
00613         if( !isblank((*this)[i]) )
00614             trim = false;
00615         if( !trim)
00616             toReturn << (*this)[i];
00617     }
00618     return toReturn;
00619 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::RTrim ( void   )  const

returns a copy with trailing whitespace removed

Returns:
the trimmed string

Definition at line 631 of file tString.cpp.

References LTrim(), and Reverse().

Referenced by Trim().

00632 {
00633     tString toReturn;
00634     toReturn = Reverse();
00635 
00636     toReturn = toReturn.LTrim();
00637     return toReturn.Reverse();
00638 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::Trim ( void   )  const

returns a copy with leading and trailing whitespace removed

Returns:
the trimmed string

Definition at line 650 of file tString.cpp.

References LTrim(), and RTrim().

Referenced by tIniFile::LoadFile(), and tPlayList::LoadPlaylist().

00651 {
00652     return LTrim().RTrim();
00653 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tString::StrPos ( const tString tofind  )  const

Get the position of a substring within this string.

Parameters:
tofind the string to find
Returns:
position of the start of the string or negative if not found

Definition at line 666 of file tString.cpp.

References Len().

Referenced by nAddress::FromString(), tIniFile::LoadFile(), tSettingRotation::ReadVal(), StrPos(), tIsInList(), and gServerMenu::Update().

00667 {
00668     if (tofind.Len() > Len()) {
00669         return -1;
00670     }
00671     for (int i=0; i<Len()-1; i++) {
00672         if ((*this)(i) == tofind(0)) {
00673             bool found = true;
00674             for (int j=0; j<tofind.Len()-1; j++) {
00675                 if ((*this)(i+j) != tofind(j))
00676                     found = false;
00677             }
00678             if (found == true)
00679                 return i;
00680         }
00681     }
00682 
00683     return -1;
00684 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tString::StrPos ( int  start,
const tString tofind 
) const

Get the position of a substring within this string.

Definition at line 686 of file tString.cpp.

References Len().

00687 {
00688     if (tofind.Len() > Len()) {
00689         return -1;
00690     }
00691     for (int i = start; i<Len()-1; i++) {
00692         if ((*this)(i) == tofind(0)) {
00693             bool found = true;
00694             for (int j=0; j<tofind.Len()-1; j++) {
00695                 if ((*this)(i+j) != tofind(j))
00696                     found = false;
00697             }
00698             if (found == true)
00699                 return i;
00700         }
00701     }
00702 
00703     return -1;
00704 }

Here is the call graph for this function:

int tString::StrPos ( const CHAR tofind  )  const

Get the position of a substring within this string.

Parameters:
tofind the string to find
Returns:
position of the start of the string or negative if not found

Definition at line 717 of file tString.cpp.

References StrPos().

00718 {
00719     return StrPos( tString ( tofind ) );
00720 }

Here is the call graph for this function:

int tString::StrPos ( int  start,
const CHAR tofind 
) const

Get the position of a substring within this string.

Definition at line 722 of file tString.cpp.

References StrPos().

00723 {
00724     return StrPos( start, tString ( tofind ) );
00725 }

Here is the call graph for this function:

tString tString::SubStr ( int  start,
int  len 
) const

Get an arbitrary substring within this string.

Parameters:
start start of string to extract
len length of string to extract
Returns:
the substring

Definition at line 739 of file tString.cpp.

References Len(), tASSERT, and tString().

Referenced by uMenuItemString::Event(), ExtractConnectionInformation(), FilterLine(), rTextField::FlushLine(), nAddress::FromString(), GeneratePrefix(), eSoundMixer::GetCurrentSong(), GetFileMimeExtension(), tConfItemBase::LoadAll(), tIniFile::LoadFile(), vValue::Registry::Registration::match(), uMenu::Message(), nServerInfoBase::NetReadThis(), PosWordRight(), tSettingRotation::ReadVal(), RemoveSubStr(), reparseforbiddencallbacks(), se_DisplayChatLocallyClient(), se_StripMatchingEnds(), SetLen(), SetSize(), st_RelocatePath(), SubStr(), tIsInList(), Truncate(), and ePlayerNetID::UpdateName().

00740 {
00741     tASSERT( start >= 0 );
00742 
00743     if (start > Len())
00744         return tString("");
00745 
00746     //if len < 0 or too long, take the whole string
00747     if ( (len + start) >= Len() ||  len < 0)
00748         len = Len() - start - 1;
00749 
00750     tString toReturn("");
00751 
00752     for (int i=start; i<(len + start); i++) {
00753         toReturn << (*this)(i);
00754     }
00755     return  toReturn;
00756 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::SubStr ( int  start  )  const

Get a substring within this string from the end.

Parameters:
start start of string to extract
Returns:
the substring from start to the end of this string

Definition at line 769 of file tString.cpp.

References Len(), and SubStr().

00770 {
00771     return SubStr (start, Len()-start-1 );
00772 }

Here is the call graph for this function:

int tString::ToInt ( size_type  pos = 0  )  const

Returns the string converted to an integer.

Parameters:
pos position to start looking at for a number
Returns:
the number

Definition at line 807 of file tString.cpp.

References ToT().

Referenced by gCommandLineJumpStartAnalyzer::Connect(), AAURLHandler::connectToServer:, nAddress::FromString(), and se_ChatShuffle().

00808 {
00809     int ret = 0;
00810     ToT( *this, ret, pos, "integer" );
00811     return ret;
00812 }

Here is the call graph for this function:

Here is the caller graph for this function:

REAL tString::ToFloat ( size_type  pos = 0  )  const

Returns the string converted to a float.

Parameters:
pos position to start looking at for a number
Returns:
the number

Definition at line 825 of file tString.cpp.

References REAL, and ToT().

00826 {
00827     REAL ret = 0;
00828     ToT( *this, ret, pos, "float" );
00829     return ret;
00830 }

Here is the call graph for this function:

int tString::CompareAlphaNumerical ( const tString a,
const tString b 
) [static]

Compares two strings alphanumerically.

Parameters:
a first string to compare
b second string to compare
Returns:
-1 if b is bigger than a, +1 if a is bigger than b, 0 if they are equal

Definition at line 866 of file tString.cpp.

References GetInt(), and Len().

00867 {
00868     int apos = 0;
00869     int bpos = 0;
00870 
00871     while ( apos < a.Len() && bpos < b.Len() )
00872     {
00873         int adigit = GetInt( a,apos );
00874         int bdigit = GetInt( b,bpos );
00875         if ( adigit < bdigit )
00876             return 1;
00877         else if ( adigit > bdigit )
00878             return -1;
00879     }
00880 
00881     if ( a.Len() - apos < b.Len() - bpos )
00882         return 1;
00883     else if ( a.Len() - apos > b.Len() - bpos )
00884         return 1;
00885     else
00886         return 0;
00887 }

Here is the call graph for this function:

tString tString::StripWhitespace ( void   )  const

Strips all whitespace from a string.

Returns:
a string with all whitespace removed. "hi everyone " -> "hieveryone"

Definition at line 899 of file tString.cpp.

References isblank(), and Len().

Referenced by tIniFile::LoadFile().

00900 {
00901     tString toReturn;
00902 
00903     for( int i = 0; i<=Len()-2; i++ )
00904     {
00905         if( !isblank((*this)(i)) )
00906             toReturn << (*this)(i);
00907     }
00908     return toReturn;
00909 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::ToLower ( void   )  const

Converts the string to lowercase.

Returns:
a string where all characters are converted to lowercase. "Hello World!" -> "hello world!"

Definition at line 912 of file tString.cpp.

Referenced by tConfItemBase::GetCommands(), and cWidget::WithDataFunctions::ProcessDataSource().

00912                                    {
00913     tString ret(*this);
00914     for(iterator iter=ret.begin(); iter!=ret.end(); ++iter) {
00915         *iter = tolower(*iter);
00916     }
00917     return ret;
00918 }

Here is the caller graph for this function:

tString tString::ToUpper ( void   )  const

Converts the string to uppercase.

Returns:
a string where all characters are converted to uppercase. "Hello World!" -> "HELLO WORLD!"

Definition at line 921 of file tString.cpp.

Referenced by tConfItemBase::FindConfigItem().

00921                                    {
00922     tString ret(*this);
00923     for(iterator iter=ret.begin(); iter!=ret.end(); ++iter) {
00924         *iter = toupper(*iter);
00925     }
00926     return ret;
00927 }

Here is the caller graph for this function:

int tString::PosWordRight ( int  start  )  const

Computes the position of the next delimiter relative to start.

Parameters:
start The location of right to search
Returns:
Position relative from start to the delimiter to the right.

Definition at line 955 of file tString.cpp.

References delimiters, Len(), and SubStr().

Referenced by uMenuItemString::Event(), PosWordLeft(), and RemoveWordRight().

00955                                            {
00956     int nextDelimiter = strcspn( SubStr( start, Len() ), delimiters );
00957     int toMove = nextDelimiter;
00958 
00959     // A delimter in our immediate path
00960     if ( toMove == 0 ) {
00961         // Move over delimiters
00962         while ( nextDelimiter == 0 && start + 1 < Len() ) {
00963             toMove++;
00964             start++;
00965             nextDelimiter = strcspn( SubStr( start, Len() ), delimiters );
00966         }
00967         // Skip over the word if not multiple delimiters
00968         if ( toMove == 1 ) {
00969             toMove += nextDelimiter;
00970         }
00971     }
00972 
00973     return toMove;
00974 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tString::PosWordLeft ( int  start  )  const

Computes the position of the previous delimiter relative to start.

Parameters:
start The location of left to search
Returns:
Position relative from start to the delimiter to the left.

Definition at line 987 of file tString.cpp.

References Len(), PosWordRight(), and Reverse().

Referenced by uMenuItemString::Event(), and RemoveWordLeft().

00987                                           {
00988     return -1 * Reverse().PosWordRight( Len() - start - 1 );
00989 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tString::RemoveWordRight ( int  start  ) 

Remove word right according to the delimiters.

Parameters:
start The location to start removing from
Returns:
Number of characters removed and to which direction x > 0 right x < 0 left

Definition at line 1004 of file tString.cpp.

References PosWordRight(), and RemoveSubStr().

Referenced by uMenuItemString::Event().

01004                                         {
01005     int removed = PosWordRight( start );
01006     RemoveSubStr( start, removed );
01007     return removed;
01008 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tString::RemoveWordLeft ( int  start  ) 

Remove word left according to the delimiters.

Parameters:
start The location to start removing from
Returns:
Number of characters removed and to which direction x > 0 right x < 0 left

Definition at line 1023 of file tString.cpp.

References PosWordLeft(), and RemoveSubStr().

Referenced by uMenuItemString::Event().

01023                                        {
01024     int removed = PosWordLeft( start );
01025     RemoveSubStr( start, removed );
01026     return removed;
01027 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tString::RemoveSubStr ( int  start,
int  length 
)

Remove a substring, in-place.

Parameters:
start The position in the string
length How many characters to delete and the direction. x > 0 deletes right x < 0 deletes left

Definition at line 1042 of file tString.cpp.

References abs(), Len(), and SubStr().

Referenced by uMenuItemString::Event(), ExtractConnectionInformation(), RemoveWordLeft(), and RemoveWordRight().

01042                                                   {
01043     int strLen = Len()-1;
01044     if ( length < 0 ) {
01045         start += length;
01046         length = abs( length );
01047     }
01048 
01049     if ( start + length > strLen || start < 0 || length == 0 ) {
01050         return;
01051     }
01052 
01053     if ( start == 0 ) {
01054         if ( strLen - length == 0 ) {
01055             *this = ("");
01056         }
01057         else {
01058             *this = SubStr( start + length, strLen );
01059         }
01060     }
01061     else {
01062         *this = SubStr( 0, start ) + SubStr( start + length, strLen );
01063     }
01064 
01065     // SetSze(strLen+1-length);
01066 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::GetFileMimeExtension (  )  const

Gets the lowercased file extension, as in a MIME type.

Parameters:
none 
Returns:
The extension of the filename represented by this string

Definition at line 1080 of file tString.cpp.

References Len(), Reverse(), SubStr(), and tString().

Referenced by eMusicTrack::LoadSong().

01080                                             {
01081     tString extension;
01082     int currentPosition = Len();
01083 
01084     bool goonie = true;
01085 
01086     if( currentPosition < 2 ) return tString("");
01087 
01088     while(goonie) {
01089         extension += SubStr(currentPosition,1);
01090         if( SubStr(currentPosition,1) == "." ) goonie = false;
01091         currentPosition--;
01092     }
01093 
01094     extension = extension.Reverse();
01095     if( extension == (*this) ) return tString("");
01096 
01097     for(size_t i=0; i<extension.size(); i++)
01098         extension[i] = tolower(extension[i]);
01099     return extension;
01100 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::Reverse (  )  const

Reverses strings.

Returns:
A copy of the string reversed

Definition at line 1112 of file tString.cpp.

References Len().

Referenced by EndsWith(), GetFileMimeExtension(), PosWordLeft(), and RTrim().

01112                                {
01113     tString reversed;
01114     for ( int index = Len() - 2; index >= 0; index-- ) {
01115         reversed << ( *this ) ( index );
01116     }
01117 
01118     return reversed;
01119 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString tString::Truncate ( int  truncateAt  )  const

Returns a truncated string (copy of this with excess chars replaced by "...").

Parameters:
truncateAt The postion to truncate at
Returns:
A new string with the truncated text and "..." concatenated
Example: tString("word").Truncate( 2 ) -> "wo..."

Definition at line 1134 of file tString.cpp.

References Len(), and SubStr().

01135 {
01136     // The string does not need to be truncated
01137     if ( truncateAt >= Len() )
01138         return *this;
01139 
01140     return SubStr( 0, truncateAt ) + "...";
01141 }

Here is the call graph for this function:

tString::CHAR tString::operator[] ( size_t  i  )  const

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1154 of file tString.cpp.

References tASSERT.

Referenced by operator[]().

01155 {
01156     tASSERT( i <= size() );
01157     return BASE::operator[]( i );
01158 }

Here is the caller graph for this function:

tString::CHAR & tString::operator[] ( size_t  i  ) 

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1171 of file tString.cpp.

References tERR_MESSAGE.

01172 {
01173     while( i >= size() )
01174     {
01175         *this += ' ';
01176 #ifdef DEBUG
01177         static bool warn = true;
01178         if( warn )
01179         {
01180             warn = false;
01181             tERR_MESSAGE("Auto-expanding string, this functionality will go away.");
01182         }
01183 #endif
01184     }
01185 
01186     return BASE::operator[](i);
01187 }

tString::CHAR tString::operator[] ( int  i  )  const

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1200 of file tString.cpp.

References operator[]().

01201 {
01202     return operator[]( size_t(i) );
01203 }

Here is the call graph for this function:

tString::CHAR & tString::operator[] ( int  i  ) 

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1216 of file tString.cpp.

References operator[]().

01217 {
01218     return operator[]( size_t(i) );
01219 }

Here is the call graph for this function:

void tString::SetSize ( unsigned int  len  ) 

sets the string length by cutting or appending spaces

Parameters:
len the desired length

Definition at line 1388 of file tString.cpp.

References SubStr(), and tASSERT.

Referenced by RemoveTrailingColor(), and SetPos().

01389 {
01390     tASSERT(len < 268435456);
01391 
01392     while ( len > size() )
01393         *this += ' ';
01394     if ( len < size() )
01395         *this = SubStr( 0, len );
01396 
01397     tASSERT( size() == len );
01398 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString::CHAR tString::operator() ( size_t  i  )  const

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1232 of file tString.cpp.

References tASSERT.

Referenced by operator()().

01233 {
01234     tASSERT( i <= size() );
01235     return BASE::operator[]( i );
01236 }

Here is the caller graph for this function:

tString::CHAR & tString::operator() ( size_t  i  ) 

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1249 of file tString.cpp.

References tASSERT.

01250 {
01251     tASSERT( i < size() );
01252     return BASE::operator[]( i );
01253 }

tString::CHAR tString::operator() ( int  i  )  const

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1266 of file tString.cpp.

References operator()().

01267 {
01268     return operator()( size_t(i) );
01269 }

Here is the call graph for this function:

tString::CHAR & tString::operator() ( int  i  ) 

Parameters:
i position to look up
Returns:
character at given position

Definition at line 1282 of file tString.cpp.

References operator()().

01283 {
01284     return operator()( size_t(i) );
01285 }

Here is the call graph for this function:

int tString::Compare ( const CHAR other  )  const

Compares two strings lexicographically.

Referenced by vValue::Registry::Registration::match().

Here is the caller graph for this function:

int tString::Compare ( const CHAR other,
bool  ignoreCase 
) const

Compares two strings lexicographically, ignoring case differences if second argument is true.

tString::operator const tString::CHAR * ( void   )  const

Returns:
the C string version of this string

Definition at line 1338 of file tString.cpp.

01339 {
01340     return c_str();
01341 }

int tString::Count ( CHAR  what  )  const

Counts the number of a certain character within the string.

Parameters:
what the character that is searched for
Returns:
the number of matching characters in the string, 0 if none

Definition at line 931 of file tString.cpp.

Referenced by rConsole::Render().

00931                                   {
00932     int ret = 0;
00933     for(const_iterator iter=begin(); iter!=end(); ++iter) {
00934         if (*iter == what)
00935             ret++;
00936     }
00937     return ret;
00938 }

Here is the caller graph for this function:

int tString::LongestLine ( void   )  const

the length of the longest line

Returns:
the length of the longest line

Reimplemented in tColoredString.

Definition at line 1359 of file tString.cpp.

References pos.

01359                                      {
01360     unsigned longest = 0;
01361     unsigned pos = 0;
01362     int l;
01363     while ((l=find_first_of('\n', pos)) != -1) {
01364         if(l-pos > longest)
01365             longest = l-pos;
01366         pos = l+1;
01367     }
01368     if(size() - pos > longest)
01369         longest = size() - pos;
01370     return longest;
01371 }

int tString::Len ( void   )  const

returns the lenghth PLUS ONE (the allocated length)

Returns:
the length including the trailing \0

Definition at line 1353 of file tString.cpp.

Referenced by tCommandLineData::Analyse(), nKrawall::BrokenScramblePassword(), CompareAlphaNumerical(), ConnectToServerCore(), EndsWith(), ePlayer::ePlayer(), uMenuItemString::Event(), ExtractConnectionInformation(), tStatFile::flushWrites(), GeneratePrefix(), tPathResource::GetDirPath(), GetFileMimeExtension(), tDirectories::GetFiles(), GetInt(), nQueryMessageStats::GetIP(), GetMyHostName(), nServerInfo::GetSmallServerInfo(), IsLegalPlayerName(), tLanguage::Load(), eWavData::Load(), tConfItemBase::LoadAll(), tIniFile::LoadFile(), tPlayList::LoadPlaylist(), uMenu::Message(), eVoter::Name(), NetFilter(), nServerInfo::NetReadThis(), nServerInfoBase::NetReadThis(), tResourceManager::openResource(), tLocaleItem::operator const char *(), operator<<(), PasswordCallback(), tPathResource::Paths(), tPathScreenshot::Paths(), tPathVar::Paths(), tPathData::Paths(), tPathConfig::Paths(), PosWordLeft(), PosWordRight(), RemoveSubStr(), gServerMenuItem::RenderBackground(), ReplacePath(), Reverse(), nServerInfo::Save(), se_AppendChat(), se_ChatShuffle(), se_EscapeName(), se_IsNameTaken(), se_ListPlayers(), se_OptionalNameFilters(), se_RequestLogin(), se_StripMatchingEnds(), se_VoteKickUser(), SetLen(), SetPos(), sg_NetworkError(), tXmlParserNamespace::st_ErrorFunc(), st_RelocatePath(), StartsWith(), StripWhitespace(), StrPos(), SubStr(), tIsInList(), Truncate(), tStringLessThan(), tToLower(), tToUpper(), uMenuItemString::uMenuItemString(), gServerMenu::Update(), eTeam::UpdateAppearance(), ePlayerNetID::UpdateName(), tConfItemLine::WriteVal(), and uMenuItemStringWithHistory::~uMenuItemStringWithHistory().

01354 {
01355     return size() + 1;
01356 }

void tString::SetLen ( int  len  ) 

sets the allocated length

Legacy function, don't use.

Parameters:
len the desired length (including the trailing )

Definition at line 1411 of file tString.cpp.

References Len(), st_Breakpoint(), SubStr(), and tASSERT.

Referenced by se_AppendChat().

01412 {
01413     // legacy function, don't use
01414     st_Breakpoint();
01415 
01416     while ( len > Len() )
01417         *this += ' ';
01418     if ( len < Len() )
01419         *this = SubStr( 0, len );
01420 
01421     tASSERT( Len() == len );
01422 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tString::NetFilter ( void   ) 

filters strings from the net for strange things like newlines

Definition at line 1646 of file tString.cpp.

References tCharacterFilter::Filter(), filter(), and Len().

Referenced by nServerInfo::DoGetFrom(), nAuthentication::HandlePasswordRequest(), ePlayerNetID::SetName(), and sn_ReadFiltered().

01647 {
01648     static tCharacterFilter filter;
01649 
01650     // run through string
01651     for( int i = Len()-2; i>=0; --i )
01652     {
01653         // character to filter
01654         char & my = (*this)(i);
01655 
01656         my = filter.Filter(my);
01657     }
01658 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:59:45 2008 for Armagetron Advanced by  doxygen 1.5.4