#include <sstring.h>
Nevrax
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. |
|
Definition at line 34 of file sstring.h. Referenced by leftCrop(), and rightCrop().
00035 { 00036 } |
|
Definition at line 38 of file sstring.h. References s.
00039 { 00040 *(std::string *)this=s; 00041 } |
|
Definition at line 43 of file sstring.h. References s.
00044 { 00045 *(std::string *)this=s; 00046 } |
|
Definition at line 48 of file sstring.h.
00049 {
00050 *(std::string *)this=c;
00051 }
|
|
Definition at line 53 of file sstring.h.
00054 { 00055 char buf[1024]; 00056 sprintf(buf,fmt,i); 00057 *this=buf; 00058 } |
|
Definition at line 60 of file sstring.h.
00061 { 00062 char buf[1024]; 00063 sprintf(buf,fmt,u); 00064 *this=buf; 00065 } |
|
Definition at line 67 of file sstring.h.
00068 { 00069 char buf[1024]; 00070 sprintf(buf,fmt,d); 00071 *this=buf; 00072 } |
|
Definition at line 74 of file sstring.h. References s.
00075 { 00076 char buf[1024]; 00077 sprintf(buf,fmt,s); 00078 *this=buf; 00079 } |
|
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 } |
|
Definition at line 561 of file sstring.h.
00562 { 00563 return ::atof(c_str()); 00564 } |
|
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 } |
|
Definition at line 550 of file sstring.h.
00551 { 00552 return ::atoi(c_str()); 00553 } |
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
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().
|
|
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().
|
|
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 } |
|
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 } |
|
Definition at line 321 of file sstring.h. References firstWord().
00322 { 00323 return const_cast<CSString *>(this)->firstWord(); 00324 } |
|
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 } |
|
Definition at line 392 of file sstring.h. References firstWordOrWords().
00393 { 00394 return const_cast<CSString *>(this)->firstWordOrWords(); 00395 } |
|
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 } |
|
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; } |
|
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 }
|
|
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.
|
|
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 } |
|
Case insensitive string compare.
Definition at line 585 of file sstring.h. References NLMISC::stricmp().
00586 { 00587 return stricmp(c_str(),other)!=0; 00588 } |
|
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 } |
|
Case insensitive string compare.
Definition at line 633 of file sstring.h. References NLMISC::stricmp().
00634 { 00635 return stricmp(c_str(),other)>0; 00636 } |
|
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 } |
|
Case insensitive string compare.
Definition at line 597 of file sstring.h. References NLMISC::stricmp().
00598 { 00599 return stricmp(c_str(),other)<=0; 00600 } |
|
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 } |
|
Case insensitive string compare.
Definition at line 573 of file sstring.h. References NLMISC::stricmp().
00574 { 00575 return stricmp(c_str(),other)==0; 00576 } |
|
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 } |
|
Case insensitive string compare.
Definition at line 621 of file sstring.h. References NLMISC::stricmp().
00622 { 00623 return stricmp(c_str(),other)>0; 00624 } |
|
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 } |
|
Case insensitive string compare.
Definition at line 609 of file sstring.h. References NLMISC::stricmp().
00610 { 00611 return stricmp(c_str(),other)>=0; 00612 } |
|
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 } |
|
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 } |
|
Return the n right hand most characters of a string.
Definition at line 103 of file sstring.h.
|
|
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().
|
|
Serial.
Definition at line 645 of file sstring.h. References s.
00646 { 00647 s.serial( reinterpret_cast<std::string&>( *this ) ); 00648 } |
|
Return sub string from character following first instance of given character on.
Definition at line 213 of file sstring.h.
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 } |
|
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 } |
|
Return sub string up to but not including first instance of given character.
Definition at line 163 of file sstring.h.
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 } |
|
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 } |
|
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().
|
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
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().
|
|
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().
|