From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a03435.html | 2802 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2802 insertions(+) create mode 100644 docs/doxygen/nel/a03435.html (limited to 'docs/doxygen/nel/a03435.html') diff --git a/docs/doxygen/nel/a03435.html b/docs/doxygen/nel/a03435.html new file mode 100644 index 00000000..a53e88a4 --- /dev/null +++ b/docs/doxygen/nel/a03435.html @@ -0,0 +1,2802 @@ + + +NeL: NLMISC::CSString class Reference + + + +
+

NLMISC::CSString Class Reference

#include <sstring.h> +

+


Detailed Description

+CSString : std::string with more functionalities and case insensitive compare

+

Author:
Daniel Miller

+Nevrax

+
Date:
2003
+ +

+ +

+Definition at line 31 of file sstring.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

double atof () const
template<class C> bool atof (C &result) const
 A couple of handy atof routines...

unsigned atoi () const
template<class C> bool atoi (C &result) const
 A couple of handy atoi routines...

char back () const
 Return the n right hand most characters of a string.

bool contains (int character) const
 Return true if this contains given sub string.

bool contains (const char *toFind) const
 Return true if this contains given sub string.

unsigned countWordOrWords () const
 Count the number of words (or quote delimited sub-strings) in a string.

unsigned countWords () const
 Count the number of words (or quote delimited sub-strings) in a string.

 CSString (const std::string &s, const char *fmt)
 CSString (const char *s, const char *fmt)
 CSString (double d, const char *fmt="%f")
 CSString (unsigned u, const char *fmt="%u")
 CSString (int i, const char *fmt="%d")
 CSString (char c)
 CSString (const std::string &s)
 CSString (const char *s)
 CSString ()
unsigned find (const char *toFind, unsigned startLocation=0) const
 Find index at which a sub-string starts (case not sensitive) - if sub-string not found then returns string::npos.

CSString firstWord (bool truncateThis=false)
 Return first word (blank separated).

CSString firstWordConst () const
CSString firstWordOrWords (bool truncateThis=false)
 Return first word or quote-encompassed sub-string.

CSString firstWordOrWordsConst () const
bool icompare (const std::string &other) const
 Case insensitive string compare (useful for use as map keys, see less<CSString> below).

CSString left (unsigned count) const
 Return the n left hand most characters of a string.

CSString leftCrop (unsigned count) const
 Return the string minus the n left hand most characters of a string.

char operator * ()
 Return the first character, or '' is the string is empty.

bool operator!= (const char *other) const
 Case insensitive string compare.

bool operator!= (const std::string &other) const
 Case insensitive string compare.

bool operator< (const char *other) const
 Case insensitive string compare.

bool operator< (const std::string &other) const
 Case insensitive string compare.

bool operator<= (const char *other) const
 Case insensitive string compare.

bool operator<= (const std::string &other) const
 Case insensitive string compare.

bool operator== (const char *other) const
 Case insensitive string compare.

bool operator== (const std::string &other) const
 Case insensitive string compare.

bool operator> (const char *other) const
 Case insensitive string compare.

bool operator> (const std::string &other) const
 Case insensitive string compare.

bool operator>= (const char *other) const
 Case insensitive string compare.

bool operator>= (const std::string &other) const
 Case insensitive string compare.

CSString replace (const char *toFind, const char *replacement) const
 Replacing all occurences of one string with another.

CSString right (unsigned count) const
 Return the n right hand most characters of a string.

CSString rightCrop (unsigned count) const
 Return the string minus the n right hand most characters of a string.

void serial (NLMISC::IStream &s)
 Serial.

CSString splitFrom (const char *s) const
 Return sub string from character following first instance of given character on.

CSString splitFrom (char c) const
 Return sub string from character following first instance of given character on.

CSString splitTo (const char *s, bool truncateThis=false)
 Return sub string up to but not including first instance of given character.

CSString splitTo (char c, bool truncateThis=false)
 Return sub string up to but not including first instance of given character.

CSString splitTo (char c) const
 Return sub string up to but not including first instance of given character.

CSString strip () const
 Return a copy of the string with leading and trainling spaces rmoved.

CSString strtok (const char *separators)
 Behave like a s strtok() routine, returning the sun string extracted from (and removed from) *this.

CSString tailFromFirstWord () const
 Return sub string up to but not including first instance of given character.

CSString tailFromFirstWordOrWords () const
 Return sub string up to but not including first instance of given character.

CSString toLower () const
 Making a lower case copy of a string.

CSString toUpper () const
 Making an upper case copy of a string.

CSString word (unsigned idx) const
 Count the number of words (or quote delimited sub-strings) in a string.

CSString wordOrWords (unsigned idx) const
 Count the number of words (or quote delimited sub-strings) in a string.


Static Public Member Functions

bool isWhiteSpace (char c)
 A handy utility routine for knowing if a character is a white space character or not.

+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
NLMISC::CSString::CSString  )  [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 34 of file sstring.h. +

+Referenced by leftCrop(), and rightCrop(). +

+

00035         {
+00036         }
+
+

+ + + + +
+ + + + + + + + + + +
NLMISC::CSString::CSString const char *  s  )  [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 38 of file sstring.h. +

+References s. +

+

00039         {
+00040                 *(std::string *)this=s;
+00041         }
+
+

+ + + + +
+ + + + + + + + + + +
NLMISC::CSString::CSString const std::string &  s  )  [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 43 of file sstring.h. +

+References s. +

+

00044         {
+00045                 *(std::string *)this=s;
+00046         }
+
+

+ + + + +
+ + + + + + + + + + +
NLMISC::CSString::CSString char  c  )  [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 48 of file sstring.h. +

+

00049         {
+00050                 *(std::string *)this=c;
+00051         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
NLMISC::CSString::CSString int  i,
const char *  fmt = "%d"
[inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 53 of file sstring.h. +

+

00054         {
+00055                 char buf[1024];
+00056                 sprintf(buf,fmt,i);
+00057                 *this=buf;
+00058         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
NLMISC::CSString::CSString unsigned  u,
const char *  fmt = "%u"
[inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 60 of file sstring.h. +

+

00061         {
+00062                 char buf[1024];
+00063                 sprintf(buf,fmt,u);
+00064                 *this=buf;
+00065         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
NLMISC::CSString::CSString double  d,
const char *  fmt = "%f"
[inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 67 of file sstring.h. +

+

00068         {
+00069                 char buf[1024];
+00070                 sprintf(buf,fmt,d);
+00071                 *this=buf;
+00072         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
NLMISC::CSString::CSString const char *  s,
const char *  fmt
[inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 74 of file sstring.h. +

+References s. +

+

00075         {
+00076                 char buf[1024];
+00077                 sprintf(buf,fmt,s);
+00078                 *this=buf;
+00079         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
NLMISC::CSString::CSString const std::string &  s,
const char *  fmt
[inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 81 of file sstring.h. +

+References s. +

+

00082         {
+00083                 char buf[1024];
+00084                 sprintf(buf,fmt,s.c_str());
+00085                 *this=buf;
+00086         }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + +
double NLMISC::CSString::atof  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 561 of file sstring.h. +

+

00562         {
+00563                 return ::atof(c_str());
+00564         }
+
+

+ + + + +
+ + + + + + + + + + + + + +
+template<class C>
bool NLMISC::CSString::atof C &  result  )  const [inline]
+
+ + + + + +
+   + + +

+A couple of handy atof routines... +

+ +

+Definition at line 556 of file sstring.h. +

+

00557         {
+00558                 result=::atof(c_str());
+00559                 return (result!=0 || *this=="0");
+00560         }
+
+

+ + + + +
+ + + + + + + + + +
unsigned NLMISC::CSString::atoi  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 550 of file sstring.h. +

+

00551         {
+00552                 return ::atoi(c_str());
+00553         }
+
+

+ + + + +
+ + + + + + + + + + + + + +
+template<class C>
bool NLMISC::CSString::atoi C &  result  )  const [inline]
+
+ + + + + +
+   + + +

+A couple of handy atoi routines... +

+ +

+Definition at line 545 of file sstring.h. +

+

00546         {
+00547                 result=::atoi(c_str());
+00548                 return (result!=0 || *this=="0");
+00549         }
+
+

+ + + + +
+ + + + + + + + + +
char NLMISC::CSString::back  )  const [inline]
+
+ + + + + +
+   + + +

+Return the n right hand most characters of a string. +

+ +

+Definition at line 97 of file sstring.h. +

+References size. +

+

00098         {
+00099                 return (*this)[size()-1];
+00100         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::contains int  character  )  const [inline]
+
+ + + + + +
+   + + +

+Return true if this contains given sub string. +

+ +

+Definition at line 535 of file sstring.h. +

+

00536         {
+00537                 for (const_iterator it=begin();it!=end();++it)
+00538                         if ((*it)==character)
+00539                                 return true;
+00540 
+00541                 return false;
+00542         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::contains const char *  toFind  )  const [inline]
+
+ + + + + +
+   + + +

+Return true if this contains given sub string. +

+ +

+Definition at line 529 of file sstring.h. +

+References find(). +

+

00530         {
+00531                 return find(toFind)!=std::string::npos;
+00532         }
+
+

+ + + + +
+ + + + + + + + + +
unsigned NLMISC::CSString::countWordOrWords  )  const [inline]
+
+ + + + + +
+   + + +

+Count the number of words (or quote delimited sub-strings) in a string. +

+ +

+Definition at line 406 of file sstring.h. +

+References count, strip(), and tailFromFirstWordOrWords(). +

+

00407         {
+00408                 unsigned count=0;
+00409                 CSString hold=strip();
+00410                 while (!hold.empty())
+00411                 {
+00412                         hold=hold.tailFromFirstWordOrWords().strip();
+00413                         ++count;
+00414                 }
+00415                 return count;
+00416         }
+
+

+ + + + +
+ + + + + + + + + +
unsigned NLMISC::CSString::countWords  )  const [inline]
+
+ + + + + +
+   + + +

+Count the number of words (or quote delimited sub-strings) in a string. +

+ +

+Definition at line 335 of file sstring.h. +

+References count, strip(), and tailFromFirstWord(). +

+

00336         {
+00337                 unsigned count=0;
+00338                 CSString hold=strip();
+00339                 while (!hold.empty())
+00340                 {
+00341                         hold=hold.tailFromFirstWord().strip();
+00342                         ++count;
+00343                 }
+00344                 return count;
+00345         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
unsigned NLMISC::CSString::find const char *  toFind,
unsigned  startLocation = 0
const [inline]
+
+ + + + + +
+   + + +

+Find index at which a sub-string starts (case not sensitive) - if sub-string not found then returns string::npos. +

+ +

+Definition at line 506 of file sstring.h. +

+References size. +

+Referenced by contains(), and NLMISC::CWordsDictionary::lookup(). +

+

00507         {
+00508                 const char *constStr = c_str();
+00509 
+00510                 // just bypass the problems that can cause a crash...
+00511                 if (toFind==NULL || *toFind==0 || startLocation>=size())
+00512                         return std::string::npos;
+00513 
+00514                 unsigned i,j;
+00515                 for (i=startLocation;i<size();++i)
+00516                 {
+00517                         // string compare toFind against (*this)+i ...
+00518                         for (j=0;toFind[j];++j)
+00519                                 if ((i+j>=size()) || (*this)[i+j]!=toFind[j])
+00520                                         break;
+00521                         // if strings were identical then we're done
+00522                         if (toFind[j]==0)
+00523                                 return i;
+00524                 }
+00525                 return std::string::npos;
+00526         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::firstWord bool  truncateThis = false  )  [inline]
+
+ + + + + +
+   + + +

+Return first word (blank separated). +

+ +

+Definition at line 284 of file sstring.h. +

+References isWhiteSpace(), and size. +

+Referenced by firstWordConst(), firstWordOrWords(), tailFromFirstWord(), and word(). +

+

00285         {
+00286                 CSString result;
+00287                 unsigned i=0;
+00288                 // skip white space
+00289                 for (i=0;i<size() && isWhiteSpace((*this)[i]);++i)
+00290                 {}
+00291 
+00292                 if ( ((*this)[i]>='A' && (*this)[i]<='Z') || ((*this)[i]>='a' && (*this)[i]<='z') || 
+00293                          ((*this)[i]>='0' && (*this)[i]<='9') || (*this)[i]=='_')
+00294                 {
+00295                         // copy out an alpha-numeric string
+00296                         for (;i<(*this).size() && 
+00297                                 ( ((*this)[i]>='A' && (*this)[i]<='Z') || ((*this)[i]>='a' && (*this)[i]<='z') || 
+00298                                   ((*this)[i]>='0' && (*this)[i]<='9') || (*this)[i]=='_')
+00299                                 ;++i)
+00300                                 result+=(*this)[i];
+00301                 }
+00302                 else
+00303                 {
+00304                         // just take the first character of the input
+00305                         result=(*this)[i];
+00306                         ++i;
+00307                 }
+00308 
+00309                 // remove the result string from the input string if so desired
+00310                 if (truncateThis)
+00311                 {
+00312                         if (i<size())
+00313                                 (*this)=substr(i);
+00314                         else
+00315                                 clear();
+00316                 }
+00317 
+00318                 return result;
+00319         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::firstWordConst  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 321 of file sstring.h. +

+References firstWord(). +

+

00322         {
+00323                 return const_cast<CSString *>(this)->firstWord();
+00324         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::firstWordOrWords bool  truncateThis = false  )  [inline]
+
+ + + + + +
+   + + +

+Return first word or quote-encompassed sub-string. +

+ +

+Definition at line 359 of file sstring.h. +

+References firstWord(), size, and strip(). +

+Referenced by firstWordOrWordsConst(), tailFromFirstWordOrWords(), and wordOrWords(). +

+

00360         {
+00361                 CSString hold=strip();
+00362                 static const CSString emptyString;
+00363 
+00364                 if (hold.empty())
+00365                         return emptyString;
+00366                 
+00367                 if (hold[0]!='\"')
+00368                         return firstWord(truncateThis);
+00369 
+00370                 // the string is quote enclosed
+00371                 CSString result;
+00372                 unsigned i=1; // skip leading quote
+00373                 // copy from character following opening quote to char preceding closing quote (or end of string)
+00374                 while (i<hold.size() && hold[i]!='\"')
+00375                 {
+00376                         result+=hold[i];
+00377                         ++i;
+00378                 }
+00379 
+00380                 // remove the result string from the input string if so desired
+00381                 if (truncateThis)
+00382                 {
+00383                         if (i<size()-1)
+00384                                 (*this)=substr(i+1);    // +1 to skip the closing quote
+00385                         else
+00386                                 clear();
+00387                 }
+00388 
+00389                 return result;
+00390         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::firstWordOrWordsConst  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 392 of file sstring.h. +

+References firstWordOrWords(). +

+

00393         {
+00394                 return const_cast<CSString *>(this)->firstWordOrWords();
+00395         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::icompare const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare (useful for use as map keys, see less<CSString> below). +

+ +

+Definition at line 639 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00640         {
+00641                 return stricmp(c_str(),other.c_str())<0;
+00642         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::isWhiteSpace char  c  )  [inline, static]
+
+ + + + + +
+   + + +

+A handy utility routine for knowing if a character is a white space character or not. +

+ +

+Definition at line 430 of file sstring.h. +

+Referenced by firstWord(), and strip(). +

+

00430 { return c==' ' || c=='\t' || c=='\n' || c=='\r' || c==26; }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::left unsigned  count  )  const [inline]
+
+ + + + + +
+   + + +

+Return the n left hand most characters of a string. +

+ +

+Definition at line 119 of file sstring.h. +

+References count. +

+

00120         {
+00121                 return substr(0,count);
+00122         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::leftCrop unsigned  count  )  const [inline]
+
+ + + + + +
+   + + +

+Return the string minus the n left hand most characters of a string. +

+ +

+Definition at line 125 of file sstring.h. +

+References count, CSString(), and size. +

+

00126         {
+00127                 if (count>=size())
+00128                         return CSString();
+00129                 return substr(count);
+00130         }
+
+

+ + + + +
+ + + + + + + + + + +
char NLMISC::CSString::operator * void   )  [inline]
+
+ + + + + +
+   + + +

+Return the first character, or '' is the string is empty. +

+ +

+Definition at line 89 of file sstring.h. +

+

00090         {
+00091                 if (empty())
+00092                         return 0;
+00093                 return (*this)[0];
+00094         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator!= const char *  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 585 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00586         {
+00587                 return stricmp(c_str(),other)!=0;
+00588         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator!= const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 579 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00580         {
+00581                 return stricmp(c_str(),other.c_str())!=0;
+00582         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator< const char *  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 633 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00634         {
+00635                 return stricmp(c_str(),other)>0;
+00636         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator< const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 627 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00628         {
+00629                 return stricmp(c_str(),other.c_str())>0;
+00630         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator<= const char *  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 597 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00598         {
+00599                 return stricmp(c_str(),other)<=0;
+00600         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator<= const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 591 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00592         {
+00593                 return stricmp(c_str(),other.c_str())<=0;
+00594         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator== const char *  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 573 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00574         {
+00575                 return stricmp(c_str(),other)==0;
+00576         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator== const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 567 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00568         {
+00569                 return stricmp(c_str(),other.c_str())==0;
+00570         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator> const char *  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 621 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00622         {
+00623                 return stricmp(c_str(),other)>0;
+00624         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator> const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 615 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00616         {
+00617                 return stricmp(c_str(),other.c_str())>0;
+00618         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator>= const char *  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 609 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00610         {
+00611                 return stricmp(c_str(),other)>=0;
+00612         }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CSString::operator>= const std::string &  other  )  const [inline]
+
+ + + + + +
+   + + +

+Case insensitive string compare. +

+ +

+Definition at line 603 of file sstring.h. +

+References NLMISC::stricmp(). +

+

00604         {
+00605                 return stricmp(c_str(),other.c_str())>=0;
+00606         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
CSString NLMISC::CSString::replace const char *  toFind,
const char *  replacement
const [inline]
+
+ + + + + +
+   + + +

+Replacing all occurences of one string with another. +

+ +

+Definition at line 475 of file sstring.h. +

+References size. +

+

00476         {
+00477                 // just bypass the problems that can cause a crash...
+00478                 if (toFind==NULL || *toFind==0)
+00479                         return *this;
+00480 
+00481                 unsigned i,j;
+00482                 CSString result;
+00483                 for (i=0;i<size();)
+00484                 {
+00485                         // string compare toFind against (*this)+i ...
+00486                         for (j=0;toFind[j];++j)
+00487                                 if ((*this)[i+j]!=toFind[j])
+00488                                         break;
+00489                         // if strings were identical then j reffers to ASCIIZ terminator at end of 'toFind'
+00490                         if (toFind[j]==0)
+00491                         {
+00492                                 if (replacement!=NULL)
+00493                                         result+=replacement;
+00494                                 i+=j;
+00495                         }
+00496                         else
+00497                         {
+00498                                 result+=(*this)[i];
+00499                                 ++i;
+00500                         }
+00501                 }
+00502                 return result;
+00503         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::right unsigned  count  )  const [inline]
+
+ + + + + +
+   + + +

+Return the n right hand most characters of a string. +

+ +

+Definition at line 103 of file sstring.h. +

+References count, and size. +

+

00104         {
+00105                 if (count>=size())
+00106                         return *this;
+00107                 return substr(size()-count);
+00108         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::rightCrop unsigned  count  )  const [inline]
+
+ + + + + +
+   + + +

+Return the string minus the n right hand most characters of a string. +

+ +

+Definition at line 111 of file sstring.h. +

+References count, CSString(), and size. +

+Referenced by NLMISC::CWordsDictionary::lookup(). +

+

00112         {
+00113                 if (count>=size())
+00114                         return CSString();
+00115                 return substr(0,size()-count);
+00116         }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CSString::serial NLMISC::IStream s  )  [inline]
+
+ + + + + +
+   + + +

+Serial. +

+ +

+Definition at line 645 of file sstring.h. +

+References s. +

+

00646         {
+00647                 s.serial( reinterpret_cast<std::string&>( *this ) );
+00648         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::splitFrom const char *  s  )  const [inline]
+
+ + + + + +
+   + + +

+Return sub string from character following first instance of given character on. +

+ +

+Definition at line 213 of file sstring.h. +

+References s, and size. +

+

00214         {
+00215                 unsigned int i;
+00216                 CSString result;
+00217                 for (i=0;i<size();++i)
+00218                 {
+00219                         // perform a quick string compare
+00220                         unsigned int j;
+00221                         for (j=0;i+j<size() && s[j]!=0 && s[j]==(*this)[i+j];++j)
+00222                         {
+00223                         }
+00224                         // if string compare matched then build and return a result
+00225                         if (s[j]==0)
+00226                         {
+00227                                 result=substr(i+j);
+00228                                 return result;
+00229                         }
+00230                 }
+00231                 return result;
+00232         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::splitFrom char  c  )  const [inline]
+
+ + + + + +
+   + + +

+Return sub string from character following first instance of given character on. +

+ +

+Definition at line 197 of file sstring.h. +

+

00198         {
+00199                 CSString result;
+00200                 std::string::const_iterator it;
+00201                 for (it=begin();it!=end() && *it!=c;++it)
+00202                 {}
+00203                 if (it!=end())
+00204                 {
+00205                         ++it;
+00206                         for (;it!=end();++it)
+00207                                 result+=*it;
+00208                 }
+00209                 return result;
+00210         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
CSString NLMISC::CSString::splitTo const char *  s,
bool  truncateThis = false
[inline]
+
+ + + + + +
+   + + +

+Return sub string up to but not including first instance of given character. +

+ +

+Definition at line 163 of file sstring.h. +

+References s, and size. +

+

00164         {
+00165                 unsigned i;
+00166                 CSString result;
+00167                 for (i=0;i<size();++i)
+00168                 {
+00169                         // perform a quick string compare
+00170                         int j;
+00171                         for (j=0;s[j]!=0 && s[j]==(&((*this)[i]))[j];++j)
+00172                         {
+00173                         }
+00174                         // if string compare matched then return result so far
+00175                         if (s[j]==0)
+00176                         {
+00177                                 // remove the result string from the input string if so desired
+00178                                 if (truncateThis)
+00179                                 {
+00180                                         if (i<size()-1)
+00181                                                 (*this)=substr(i+1);    // +1 to skip the separator character
+00182                                         else
+00183                                                 clear();
+00184                                 }
+00185 
+00186                                 return result;
+00187                         }
+00188                         result+=(*this)[i];
+00189                 }
+00190                 // we didn't find the separator string so we're returning a copy of the whole string
+00191                 if (truncateThis)
+00192                         clear();
+00193                 return result;
+00194         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
CSString NLMISC::CSString::splitTo char  c,
bool  truncateThis = false
[inline]
+
+ + + + + +
+   + + +

+Return sub string up to but not including first instance of given character. +

+ +

+Definition at line 143 of file sstring.h. +

+References size. +

+

00144         {
+00145                 unsigned i;
+00146                 CSString result;
+00147                 for (i=0;i<size() && (*this)[i]!=c;++i)
+00148                         result+=(*this)[i];
+00149 
+00150                 // remove the result string from the input string if so desired
+00151                 if (truncateThis)
+00152                 {
+00153                         if (i<size()-1)
+00154                                 (*this)=substr(i+1);    // +1 to skip the separator character
+00155                         else
+00156                                 clear();
+00157                 }
+00158 
+00159                 return result;
+00160         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::splitTo char  c  )  const [inline]
+
+ + + + + +
+   + + +

+Return sub string up to but not including first instance of given character. +

+ +

+Definition at line 133 of file sstring.h. +

+References size. +

+Referenced by NLMISC::CWordsDictionary::getWordsKey(). +

+

00134         {
+00135                 unsigned i;
+00136                 CSString result;
+00137                 for (i=0;i<size() && (*this)[i]!=c;++i)
+00138                         result+=(*this)[i];
+00139                 return result;
+00140         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::strip  )  const [inline]
+
+ + + + + +
+   + + +

+Return a copy of the string with leading and trainling spaces rmoved. +

+ +

+Definition at line 433 of file sstring.h. +

+References isWhiteSpace(), and size. +

+Referenced by countWordOrWords(), countWords(), firstWordOrWords(), word(), and wordOrWords(). +

+

00434         {
+00435                 CSString result;
+00436                 int i,j;
+00437                 for (j=size()-1; j>=0 && isWhiteSpace((*this)[j]); --j) {}
+00438                 for (i=0;                i<j  && isWhiteSpace((*this)[i]); ++i) {}
+00439                 for (; i<=j; ++i)
+00440                         result+=(*this)[i];
+00441                 return result;
+00442         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::strtok const char *  separators  )  [inline]
+
+ + + + + +
+   + + +

+Behave like a s strtok() routine, returning the sun string extracted from (and removed from) *this. +

+ +

+Definition at line 235 of file sstring.h. +

+References size. +

+

00236         {
+00237                 unsigned int i;
+00238                 CSString result;
+00239 
+00240                 // skip leading junk
+00241                 for (i=0;i<size();++i)
+00242                 {
+00243                         // look for the next character in the 'separator' character list supplied
+00244                         unsigned j;
+00245                         for (j=0;separators[j] && (*this)[i]!=separators[j];++j)
+00246                         {}
+00247                         // if not found then we're at end of leading junk
+00248                         if (!separators[j])
+00249                                 break;
+00250                 }
+00251 
+00252                 // copy out everything up to the next separator character
+00253                 for (;i<size();++i)
+00254                 {
+00255                         // look for the next character in the 'separator' character list supplied
+00256                         unsigned j;
+00257                         for (j=0;separators[j] && (*this)[i]!=separators[j];++j)
+00258                         {}
+00259                         // if not found then we're at end of leading junk
+00260                         if (separators[j])
+00261                                 break;
+00262                         result+=(*this)[i];
+00263                 }
+00264 
+00265                 // skip trailing junk
+00266                 for (;i<size();++i)
+00267                 {
+00268                         // look for the next character in the 'separator' character list supplied
+00269                         unsigned j;
+00270                         for (j=0;separators[j] && (*this)[i]!=separators[j];++j)
+00271                         {}
+00272                         // if not found then we're at end of leading junk
+00273                         if (!separators[j])
+00274                                 break;
+00275                 }
+00276 
+00277                 // delete the treated bit from this string
+00278                 (*this)=substr(i);
+00279 
+00280                 return result;
+00281         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::tailFromFirstWord  )  const [inline]
+
+ + + + + +
+   + + +

+Return sub string up to but not including first instance of given character. +

+ +

+Definition at line 327 of file sstring.h. +

+References firstWord(). +

+Referenced by countWords(), and word(). +

+

00328         {
+00329                 CSString hold=*this;
+00330                 hold.firstWord(true);
+00331                 return hold;
+00332         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::tailFromFirstWordOrWords  )  const [inline]
+
+ + + + + +
+   + + +

+Return sub string up to but not including first instance of given character. +

+ +

+Definition at line 398 of file sstring.h. +

+References firstWordOrWords(). +

+Referenced by countWordOrWords(), and wordOrWords(). +

+

00399         {
+00400                 CSString hold=*this;
+00401                 hold.firstWordOrWords(true);
+00402                 return hold;
+00403         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::toLower  )  const [inline]
+
+ + + + + +
+   + + +

+Making a lower case copy of a string. +

+ +

+Definition at line 460 of file sstring.h. +

+

00461         {
+00462                 CSString result;
+00463                 std::string::const_iterator it;
+00464                 for (it=begin();it!=end();++it)
+00465                 {
+00466                         char c=(*it);
+00467                         if (c>='A' && c<='Z')
+00468                                 c^=('a'^'A');
+00469                         result+=c;
+00470                 }
+00471                 return result;
+00472         }
+
+

+ + + + +
+ + + + + + + + + +
CSString NLMISC::CSString::toUpper  )  const [inline]
+
+ + + + + +
+   + + +

+Making an upper case copy of a string. +

+ +

+Definition at line 445 of file sstring.h. +

+

00446         {
+00447                 CSString result;
+00448                 std::string::const_iterator it;
+00449                 for (it=begin();it!=end();++it)
+00450                 {
+00451                         char c=(*it);
+00452                         if (c>='a' && c<='z')
+00453                                 c^=('a'^'A');
+00454                         result+=c;
+00455                 }
+00456                 return result;
+00457         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::word unsigned  idx  )  const [inline]
+
+ + + + + +
+   + + +

+Count the number of words (or quote delimited sub-strings) in a string. +

+ +

+Definition at line 348 of file sstring.h. +

+References count, firstWord(), strip(), and tailFromFirstWord(). +

+

00349         {
+00350                 CSString hold=strip();
+00351 
+00352                 for (unsigned count=0;count<idx;++count)
+00353                         hold=hold.tailFromFirstWord().strip();
+00354 
+00355                 return hold.firstWord();
+00356         }
+
+

+ + + + +
+ + + + + + + + + + +
CSString NLMISC::CSString::wordOrWords unsigned  idx  )  const [inline]
+
+ + + + + +
+   + + +

+Count the number of words (or quote delimited sub-strings) in a string. +

+ +

+Definition at line 419 of file sstring.h. +

+References count, firstWordOrWords(), strip(), and tailFromFirstWordOrWords(). +

+

00420         {
+00421                 CSString hold=strip();
+00422                 
+00423                 for (unsigned count=0;count<idx;++count)
+00424                         hold=hold.tailFromFirstWordOrWords().strip();
+00425 
+00426                 return hold.firstWordOrWords();
+00427         }
+
+


The documentation for this class was generated from the following file: +
Generated on Tue Mar 16 13:34:04 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1