src/tools/tString.h File Reference

#include "aa_config.h"
#include "defs.h"
#include <string>
#include <sstream>
#include <iostream>
#include <iosfwd>

Include dependency graph for tString.h:

Go to the source code of this file.

Classes

class  tString
 string class: standard string with some extras More...
struct  tColoredStringProxy
 proxy class for inserting color markings More...
class  tColoredString
 strings that know about color markings More...

Defines

#define WRAP_MUTATING_OPERATOR(op, T)   inline THISCLASS & operator op( T t ){ static_cast< BASE & >( *this ) op t; return *this; }
 wraps a mutating operator (+=, -=, *=). op is the operator and T the argument type.
#define WRAP_MUTATING_OPERATOR_ALLTYPES(op)   template< class T > WRAP_MUTATING_OPERATOR(op, T const &)
 wraps a mutating operator (+=, -=, *=) for all argument types. op is the operator.
#define WRAP_OPERATOR(op, T)   inline THISCLASS operator op( T t ) const { return THISCLASS( static_cast< const BASE & >( *this ) op t ); }
 wraps a non-mutating binary operator (+, -, *). op is the operator and T the second argument.
#define WRAP_OPERATOR_ALLTYPES(op)   template< class T > WRAP_OPERATOR(op, T const &)
 wraps a non-mutating binary operator (+, -, *) for second arguments. op is the operator.

Functions

bool tIsInList (tString const &list, tString const &item)
 check whether item is in a comma or whitespace separated list
void tToLower (tString &toTransform)
 converts a string to lowercase
void tToUpper (tString &toTransform)
 converts a string to uppercase
template<class T>
tStringoperator<< (tString &s, const T &c)
 string building streaming operator
tColoredStringoperator<< (tColoredString &s, const tColoredStringProxy &colorCode)
 string building streaming operator
template<class T>
tColoredStringoperator<< (tColoredString &s, const T &c)
 string building streaming operator
std::istream & operator>> (std::istream &s, tString &x)
 stream reading operator honoring escape sequences and quoting


Define Documentation

#define WRAP_MUTATING_OPERATOR ( op,
 )     inline THISCLASS & operator op( T t ){ static_cast< BASE & >( *this ) op t; return *this; }

wraps a mutating operator (+=, -=, *=). op is the operator and T the argument type.

Definition at line 46 of file tString.h.

#define WRAP_MUTATING_OPERATOR_ALLTYPES ( op   )     template< class T > WRAP_MUTATING_OPERATOR(op, T const &)

wraps a mutating operator (+=, -=, *=) for all argument types. op is the operator.

Definition at line 48 of file tString.h.

#define WRAP_OPERATOR ( op,
 )     inline THISCLASS operator op( T t ) const { return THISCLASS( static_cast< const BASE & >( *this ) op t ); }

wraps a non-mutating binary operator (+, -, *). op is the operator and T the second argument.

Definition at line 51 of file tString.h.

#define WRAP_OPERATOR_ALLTYPES ( op   )     template< class T > WRAP_OPERATOR(op, T const &)

wraps a non-mutating binary operator (+, -, *) for second arguments. op is the operator.

Definition at line 53 of file tString.h.


Function Documentation

template<class T>
tColoredString& operator<< ( tColoredString s,
const T &  c 
) [inline]

string building streaming operator

Definition at line 248 of file tString.h.

References tColoredString::RemoveTrailingColor().

00249 {
00250     // delegate to basic string function...
00251     static_cast< tString& >( s ) << c;
00252 
00253     // but don't allow overhanging color codes
00254     s.RemoveTrailingColor();
00255 
00256     return s;
00257 }

Here is the call graph for this function:

tColoredString& operator<< ( tColoredString s,
const tColoredStringProxy colorCode 
)

string building streaming operator

Appends a color code to a colored string

Parameters:
s the string to append to
colorCode the colorcode to append

Definition at line 1694 of file tString.cpp.

References tColoredStringProxy::b_, cs, tColoredStringProxy::g_, int_to_hex(), tColoredStringProxy::r_, and RTC().

01695 {
01696     if (st_colorStrings)
01697     {
01698         char cs[9];
01699         cs[0]='0';
01700         cs[1]='x';
01701 
01702         int RGB[3];
01703         RGB[0]=RTC(colorCode.r_);
01704         RGB[1]=RTC(colorCode.g_);
01705         RGB[2]=RTC(colorCode.b_);
01706 
01707         for(int i=0;i<3;i++){
01708             int lp=RGB[i]%16;
01709             int hp=(RGB[i]-lp)/16;
01710             cs[2+2*i]=int_to_hex(hp);
01711             cs[2+2*i+1]=int_to_hex(lp);
01712         }
01713         cs[8]=0;
01714 
01715         s << cs;
01716     }
01717 
01718     return s;
01719 }

Here is the call graph for this function:

template<class T>
tString& operator<< ( tString s,
const T &  c 
) [inline]

string building streaming operator

Definition at line 235 of file tString.h.

00236 {
00237     std::ostringstream S;
00238 
00239     S << c;
00240 
00241     return s += S.str();
00242 }

std::istream& operator>> ( std::istream &  s,
tString x 
)

stream reading operator honoring escape sequences and quoting

Todo:
write symmetric stream writing operator
Parameters:
s stream to read from
x string to read to
Returns:
reference to stream for chaining

Definition at line 111 of file tString.cpp.

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

00112 {
00113     x.Clear();
00114 
00115     std::ws(s);
00116 
00117     char c=s.get();
00118 
00119     // check if the string is quoted
00120     bool quoted = false;
00121     char quoteChar = c;   // if it applies, this is the quoting character
00122     if ( c == '"' || c == '\'' )
00123     {
00124         // yes, it is
00125         quoted = true;
00126         c = s.get();
00127     }
00128 
00129     while((quoted || !( isblank(c) || c == '\n' || c == '\r' ) ) && s.good() && !s.eof()){
00130         x += c;
00131         c=s.get();
00132 
00133         // read and interpret escape sequences
00134         if ( !st_ReadEscapeSequence( c, s) )
00135         {
00136             // interpret special characters
00137             if ( quoted && c == quoteChar )
00138             {
00139                 // this marks the end of a quoted string; abort.
00140                 c = s.get();
00141                 break;
00142             }
00143         }
00144         else if ( isblank( c ) )
00145         {
00146             // include escaped spaces
00147             x += c;
00148             c=s.get();
00149         }
00150 
00151     }
00152     s.putback(c);
00153     return s;
00154 }

Here is the call graph for this function:

bool tIsInList ( tString const &  list_,
tString const &  item 
)

check whether item is in a comma or whitespace separated list

Parameters:
list The string representation of the list
item The item to look for
Returns:
true if the list contains the item
Example: tIsInList( "ab, cd", "ab" ) -> true

Definition at line 2166 of file tString.cpp.

References isblank(), tString::Len(), pos, tString::StrPos(), and tString::SubStr().

Referenced by sn_BothHave(), and sn_GetSupportedMethods().

02167 {
02168     tString list = list_;
02169 
02170     while( list != "" )
02171     {
02172         // find the item
02173         int pos = list.StrPos( item );
02174 
02175         // no traditional match? shoot.
02176         if ( pos < 0 )
02177         {
02178             return false;
02179         }
02180 
02181         // check whether the match is a true list match
02182         if ( 
02183             ( pos == 0 || list[pos-1] == ',' || isblank(list[pos-1]) )
02184             &&
02185             ( pos + item.Len() >= list.Len() || list[pos+item.Len()-1] == ',' || isblank(list[pos+item.Len()-1]) )
02186             )
02187         {
02188             return true;
02189         }
02190         else
02191         {
02192             // no? truncate the list and go on.
02193             list = list.SubStr( pos + 1 );
02194         }
02195     }
02196     
02197     return false;
02198 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tToLower ( tString toTransform  ) 

converts a string to lowercase

Parameters:
toTransform The string to transform

Definition at line 2209 of file tString.cpp.

References tString::Len().

Referenced by eVoter::HandleChat(), nKrawall::nMethod::nMethod(), tConfItemBase::tConfItemBase(), and uAction::uAction().

02210 {
02211     for( int i = toTransform.Len()-2; i >= 0; --i )
02212     {
02213         toTransform[i] = tolower( toTransform[i] );
02214     }
02215 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tToUpper ( tString toTransform  ) 

converts a string to uppercase

Parameters:
toTransform The string to transform

Definition at line 2226 of file tString.cpp.

References tString::Len().

Referenced by tConfItemBase::LoadLine(), and s_Veto().

02227 {
02228     for( int i = toTransform.Len()-2; i >= 0; --i )
02229     {
02230         toTransform[i] = toupper( toTransform[i] );
02231     }
02232 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sat Mar 15 23:12:47 2008 for Armagetron Advanced by  doxygen 1.5.4