GCpp general purpose C++ library  version 1.0
GString Class Reference

#include <GString.hh>

Inheritance diagram for GString:
GOptionString

Public Member Functions

template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
virtual GStringClone () const
 
virtual const char * ClassName () const
 
 GString ()
 
 GString (const string &s)
 
 GString (const char *s)
 
 GString (const GString &s)
 
GStringoperator= (const GString &s)
 
GStringoperator= (const string &s)
 
GStringoperator= (const char *s)
 
virtual ~GString ()
 
virtual GString ToLower () const
 
virtual GString ToUpper () const
 
virtual GString NoAccent () const
 
virtual GString NoPunct (const string &punct=",;:.!?", const char rep= ' ') const
 
virtual GString NoSpace (const string &spc=" \n\t\r") const
 
virtual GString NoEndSpace (const string &spc=" \n\t\r") const
 
virtual GString Fill (size_t len, const char c= ' ', bool trunc=false) const
 
size_t FindFirstOf (const string &s, size_t index=0)
 
GStringReplaceChar (char c, char r, u_int n=0)
 
GStringReplaceAll (const GString &s, const GString &r)
 
virtual int Compare (const GString &str) const
 
virtual int CompareDict (const GString &str) const
 
virtual int ReadInt (int default_val=0) const
 
virtual float ReadFloat (float default_val=0.) const
 
virtual double ReadDouble (double default_val=0.) const
 
virtual int ReadSubInt (size_t &ifirst, size_t &ilast, size_t index=0, int default_val=0, const string &separ=" \n\t\r") const
 
virtual float ReadSubFloat (size_t &ifirst, size_t &ilast, const size_t index=0, const float default_val=0., const string &separ=" \n\t\r") const
 
virtual double ReadSubDouble (size_t &ifirst, size_t &ilast, const size_t index=0, const double default_val=0., const string &separ=" \n\t\r") const
 
virtual GString GetSubstring (char first, char last, size_t &ifirst, size_t &ilast, size_t index=0, bool keep=true) const
 
virtual GString GetSubstring (char first, char last, size_t index=0, bool keep=true) const
 
virtual GString GetWord (size_t &ifirst, size_t &ilast, size_t index=0, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual GString GetWord (size_t index=0, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual u_int CountWords (const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual u_int GetWords (string *table, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual string * CreateWordsTable (u_int &nw, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual size_t FindFormat (const char fmtc, size_t &fmtlen, size_t &len)
 
virtual size_t FindFormat (const char fmtc, size_t &fmtlen)
 
virtual GString ReplaceFormat (const char fmtc, const int val, const char spc= '0')
 

Static Public Member Functions

static const char * StaticClassName ()
 

Detailed Description

Class deriving from the standard C++ string class, defining new functions.

Constructor & Destructor Documentation

GString::GString ( )
inline

Default constructor: empty string.

GString::GString ( const string &  s)
inline

Copy constructor of a std::string object.

Parameters
sstring to copy
GString::GString ( const char *  s)
inline

Copy constructor of a C (char *) string.

Parameters
sstring to copy
GString::GString ( const GString s)
inline

Copy constructor of a GString object.

Parameters
sstring to copy
GString::~GString ( )
inlinevirtual

Destructor.

Member Function Documentation

int GString::Compare ( const GString str) const
virtual

Comparison function: it returns -1, 0 or 1 depending if the object name is lower, equal or bigger than the argument string.

Parameters
strstring to compare with

Referenced by GNamedListT< T >::Compare().

int GString::CompareDict ( const GString str) const
virtual

Alphabetical comparison function, with no distinction between upper and lower case, with no accents. Only if words are identical, the accents first, then upper/lower cases are tested.

Parameters
strstring to compare with

References NoAccent(), NoPunct(), and ToLower().

Referenced by GNamedListT< T >::Compare().

u_int GString::CountWords ( const string &  separ = " ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
virtual

Function returning the number of words in a string, and store them in an array of strings.

Parameters
separlist of space characters

References GetWords().

Referenced by CreateWordsTable().

string * GString::CreateWordsTable ( u_int nw,
const string &  separ = " ,;:.!?'[]{}()=+-*&%$#\n\t\r" 
) const
virtual

Function allocating an array of strings containing the words of the current string. It returns the pointer to the array, or NULL if there's no word. The array must be freed after use. The argument nw receives the number of words (which is the array size).

Parameters
nwnumber of words found (as function output)
separlist of space characters

References CountWords(), and GetWords().

GString GString::Fill ( size_t  len,
const char  c = ' ',
bool  trunc = false 
) const
virtual

Fill the string with a character until it's size reach the required length. If the string length is already greater or equal to the required length, the returned string is the current string (truncated to this length according to truncation argument).

Parameters
lenrequired length
cfill character
truncindicates if the returned string should be truncated to len
size_t GString::FindFirstOf ( const string &  s,
size_t  index = 0 
)
inline

Returns the position of the first character from the argument string.

Parameters
slist of characters to look for
indexstart search position
size_t GString::FindFormat ( const char  fmtc,
size_t &  fmtlen,
size_t &  len 
)
virtual

The function searches in the string for a format identifier. It should look like "%X" or "%nX", where n is an integer indicating the format size, and X is the identification character. The function returns the position where the format indication is found, or string::npos if the format is not present.

Parameters
fmtcletter (character) for the format
fmtlenlength of the format (as function output)
lenlength of the format indication (as function output)

References ReadInt().

Referenced by FindFormat(), and ReplaceFormat().

size_t GString::FindFormat ( const char  fmtc,
size_t &  fmtlen 
)
inlinevirtual

The function searches in the string for a format identifier. It should look like "%X" or "%nX", where n is an integer indicating the format size, and X is the identification character. The function returns the position where the format indication is found, or string::npos if the format is not present.

Parameters
fmtcletter (character) for the format
fmtlenlength of the format (as function output)

References FindFormat().

GString GString::GetSubstring ( char  first,
char  last,
size_t &  ifirst,
size_t &  ilast,
size_t  index = 0,
bool  keep = true 
) const
virtual

Extract a sub-string, limited by given start and stop characters. A charater '\0' as start or stop means any character: for start, the first character is accepted, and for stop, the extraction goes to the end of the string. According to argument keep, the start/stop characters are included in the result string.

Parameters
firststart (beginning) character
laststop (end) character
ifirstposition of start character (as function output)
ilastposition of stop character (as function output)
indexstart search position
keepindicates if the result contains the start/stop characters

Referenced by GIntervalList::Add(), GetSubstring(), GInterval::GInterval(), and GIntervalList::Remove().

GString GString::GetSubstring ( char  first,
char  last,
size_t  index = 0,
bool  keep = true 
) const
virtual

Extract a sub-string, limited by given start and stop characters. A charater '\0' as start or stop means any character: for start, the first character is accepted, and for stop, the extraction goes to the end of the string. According to argument keep, the start/stop characters are included in the result string.

Parameters
firststart (beginning) character
laststop (end) character
indexstart search position
keepindicates if the result contains the start/stop characters

References GetSubstring().

GString GString::GetWord ( size_t &  ifirst,
size_t &  ilast,
size_t  index = 0,
const string &  separ = " ,;:.!?'[]{}()=+-*&%$#\n\t\r" 
) const
virtual

Extract a word, limited by space characters.

Parameters
ifirstposition of 1st character of the word (as function output)
ilastposition of last character of the word (as function output)
indexstart search position
separlist of space characters

Referenced by GetWord(), GStringList::GStringList(), ReadSubDouble(), ReadSubFloat(), and ReadSubInt().

GString GString::GetWord ( size_t  index = 0,
const string &  separ = " ,;:.!?'[]{}()=+-*&%$#\n\t\r" 
) const
virtual

Extract a word, limited by space characters.

Parameters
indexstart search position
separlist of space characters

References GetWord().

u_int GString::GetWords ( string *  table,
const string &  separ = " ,;:.!?'[]{}()=+-*&%$#\n\t\r" 
) const
virtual

Function returning the number of words in a string, and store them in an array of strings. The array size is not checked. Use function CreateWordsTable to allocate an array with the exact size. If the pointertable is NULL, the words are not copied, only counted.

Parameters
tablewords arry (output)
separlist of space characters

Referenced by CountWords(), and CreateWordsTable().

template<class Q >
bool GString::IsInstanceOf ( ) const
inline

Macro from GCpp library that defines the following functions:

  • ClassName(): return the real class name of the object
  • StaticClassName(): return the used class name of the object (that may be a base class of the real object).
  • IsInstanceOf<T>(): return true if the current object is an instance of the template class name argument
  • Clone(): return an allocated copy of the object.
GString GString::NoAccent ( ) const
virtual

Return a copy of the string where all accents have been removed.

References GSTRING_ACCENT_LIST, and GSTRING_NO_ACCENT_LIST.

Referenced by CompareDict().

GString GString::NoEndSpace ( const string &  spc = " \n\t\r") const
virtual

Return a copy of the string where space characters have been suppressed at the beginning and the end of the string.

Parameters
spclist of space characters

Referenced by GInterval::GInterval().

GString GString::NoPunct ( const string &  punct = ",;:.!?",
const char  rep = ' ' 
) const
virtual

Return a copy of the string where punctuation characters have been replaced by a character (default is space).

Parameters
punctlist of characters to replace
repreplacement character ('\0' to suppress instead of replace)

Referenced by CompareDict().

GString GString::NoSpace ( const string &  spc = " \n\t\r") const
virtual

Return a copy of the string where space characters have been suppressed.

Parameters
spclist of space characters
GString & GString::operator= ( const GString s)
inline

Affectation operator.

Parameters
sstring to be affected to current object
GString & GString::operator= ( const string &  s)
inline

Affectation operator.

Parameters
sstring to be affected to current object
schaîne à affecter
GString & GString::operator= ( const char *  s)
inline

Affectation operator.

Parameters
sstring to be affected to current object
double GString::ReadDouble ( double  default_val = 0.) const
virtual

Read a real number (double) from the string.

Parameters
default_valreturned value in case of problem

Referenced by GOptionString::CheckOption(), GOptionString::ExtractOption(), and ReadSubDouble().

float GString::ReadFloat ( float  default_val = 0.) const
virtual

Read a real number (float) from the string.

Parameters
default_valreturned value in case of problem

Referenced by ReadSubFloat().

int GString::ReadInt ( int  default_val = 0) const
virtual

Read an integer (int) from the string.

Parameters
default_valreturned value in case of problem

Referenced by GOptionString::CheckOption(), GOptionString::ExtractOption(), FindFormat(), GInterval::GInterval(), and ReadSubInt().

double GString::ReadSubDouble ( size_t &  ifirst,
size_t &  ilast,
const size_t  index = 0,
const double  default_val = 0.,
const string &  separ = " \n\t\r" 
) const
virtual

Read real number (double) from the string.

Parameters
ifirstfound position of the 1st character (as function output)
ilastfound position of the last character (as function output)
indexstart search position
default_valreturned value in case of problem
separlist of separator characters

References GetWord(), and ReadDouble().

float GString::ReadSubFloat ( size_t &  ifirst,
size_t &  ilast,
const size_t  index = 0,
const float  default_val = 0.,
const string &  separ = " \n\t\r" 
) const
virtual

Read real number (float) from the string.

Parameters
ifirstfound position of the 1st character (as function output)
ilastfound position of the last character (as function output)
indexstart search position
default_valreturned value in case of problem
separlist of separator characters

References GetWord(), and ReadFloat().

int GString::ReadSubInt ( size_t &  ifirst,
size_t &  ilast,
size_t  index = 0,
int  default_val = 0,
const string &  separ = " \n\t\r" 
) const
virtual

Read an integer (int) from the string.

Parameters
ifirstfound position of the 1st character (as function output)
ilastfound position of the last character (as function output)
indexstart search position
default_valreturned value in case of problem
separlist of separator characters

References GetWord(), and ReadInt().

GString & GString::ReplaceAll ( const GString s,
const GString r 
)

Replace all occurences of the sub-string s by the string r.

Parameters
sstring to replace
rreplacement string
GString & GString::ReplaceChar ( char  c,
char  r,
u_int  n = 0 
)

Replace character c by character r. If n is not 0, it is the maximum number of occurences that are replaced (else, they are all replaced).

Parameters
ccharacter to replace
rreplacement character
nmaximum number of replacements
GString GString::ReplaceFormat ( const char  fmtc,
const int  val,
const char  spc = '0' 
)
virtual

Replace a format indication (like "%X" or "%nX") with an integer value.

Parameters
fmtcletter (character) for the format
valinteger value to fill the format
spccharacter to fill spaces (if format length is included)

References FindFormat(), and GGetString().

GString GString::ToLower ( ) const
virtual

Return a lower case copy of the string.

References GSTRING_ACCENT_LOWER, and GSTRING_ACCENT_UPPER.

Referenced by CompareDict().

GString GString::ToUpper ( ) const
virtual

Return a upper case copy of the string.

References GSTRING_ACCENT_LOWER, and GSTRING_ACCENT_UPPER.

Referenced by GOptionString::OptPosition().


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