00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef CEYLAN_STRING_UTILS_H_
00028 #define CEYLAN_STRING_UTILS_H_
00029
00030
00031 #include "CeylanTypes.h"
00032 #include "CeylanException.h"
00033
00034
00035 #include <sstream>
00036 #include <string>
00037 #include <list>
00038 #include <map>
00039
00040
00041
00042 #define CEYLAN_DEBUG_STRING_TO_OBJECT 1
00043
00044
00045
00057 namespace Ceylan
00058 {
00059
00060
00062 class CEYLAN_DLL StringUtilsException: public Exception
00063 {
00064
00065 public:
00066
00067 StringUtilsException( const std::string & message ) :
00068 Exception( message )
00069 {
00070
00071 }
00072
00073 virtual ~StringUtilsException() throw()
00074 {
00075
00076 }
00077
00078 } ;
00079
00080
00081
00086 typedef Ceylan::Uint8 Latin1Char ;
00087
00088
00089
00095 typedef std::string::size_type StringSize ;
00096
00097
00098
00109 extern CEYLAN_DLL const std::string BatchTestOption ;
00110
00111
00112
00113
00114
00115
00116
00135 CEYLAN_DLL std::string formatStringList(
00136 const std::list<std::string> & stringList,
00137 bool surroundByTicks = false ) ;
00138
00139
00140
00157 CEYLAN_DLL std::string formatStringMap(
00158 const std::map<std::string, std::string> & stringMap,
00159 bool surroundByTicks = false ) ;
00160
00161
00162
00163
00164
00165
00178 CEYLAN_DLL void display( const std::string & message ) ;
00179
00180
00181
00189 CEYLAN_DLL void displayError( const std::string & errorMessage ) ;
00190
00191
00192
00198 CEYLAN_DLL StringSize countChars( const std::string & aString,
00199 char targetChar ) ;
00200
00201
00202
00209 CEYLAN_DLL std::string reverse( const std::string & source ) ;
00210
00211
00212
00250 CEYLAN_DLL char * getNonConstCharFrom( const std::string & source ) ;
00251
00252
00253
00261 CEYLAN_DLL StringSize substituteInString(
00262 std::string & targetString,
00263 const std::string & toBeReplaced,
00264 const std::string & replacement ) ;
00265
00266
00267
00276 CEYLAN_DLL std::string substituteIn(
00277 const std::string & sourceString,
00278 const std::string & toBeReplaced,
00279 const std::string & replacement ) ;
00280
00281
00282
00292 CEYLAN_DLL bool isLetter( char targetChar ) ;
00293
00294
00295
00304 CEYLAN_DLL bool isFigure( char targetChar ) ;
00305
00306
00307
00317 CEYLAN_DLL bool isAlphanumeric( char targetChar ) ;
00318
00319
00320
00331 CEYLAN_DLL bool isPunctuation( char targetChar ) ;
00332
00333
00334
00344 CEYLAN_DLL bool isWhitespace( char targetChar ) ;
00345
00346
00347
00353 CEYLAN_DLL std::string toUppercase( const std::string & text ) ;
00354
00355
00356
00363 CEYLAN_DLL std::string encodeToHTML( const std::string & message ) ;
00364
00365
00366
00378 CEYLAN_DLL std::string encodeToPhonetic( const std::string & message ) ;
00379
00380
00381
00394 CEYLAN_DLL std::string encodeToROT13( const std::string & message ) ;
00395
00396
00397
00408 CEYLAN_DLL std::string demangleSymbol( const std::string & symbol ) ;
00409
00410
00411
00421 CEYLAN_DLL std::list<std::string> split( const std::string & stringToSplit,
00422 char splittingChar ) ;
00423
00424
00425
00435
00436
00437
00438
00439
00440
00441
00451 CEYLAN_DLL std::string join( const std::list<std::string> & toJoin,
00452 const std::string & joiningString ) ;
00453
00454
00455
00472 CEYLAN_DLL std::list<std::string> splitIntoWords(
00473 const std::string & sentenceToSplit ) ;
00474
00475
00476
00489 CEYLAN_DLL std::list<std::string> splitIntoParagraphs(
00490 const std::string & textToSplit ) ;
00491
00492
00493
00498 template <typename T>
00499 std::string toString( const std::list<T> & targetList )
00500 {
00501
00502 std::list<std::string> res ;
00503
00504 for ( typename std::list<T>::const_iterator it = targetList.begin() ;
00505 it != targetList.end(); it++ )
00506 res.push_back( Ceylan::toString( *it ) ) ;
00507
00508 return "[ " + join( res, ", " ) + " ]" ;
00509
00510 }
00511
00512
00513
00520 template <typename T>
00521 void stringToObject( const std::string & source, T & object )
00522 {
00523
00524 std::istringstream iss( source ) ;
00525 iss >> object ;
00526
00527 #if CEYLAN_DEBUG_STRING_TO_OBJECT
00528
00529 if ( iss.fail() )
00530 {
00531 throw Ceylan::Exception(
00532 "Conversion error in Ceylan string utilities "
00533 "while using template stringToObject." ) ;
00534 }
00535
00536 #endif // CEYLAN_DEBUG_STRING_TO_OBJECT
00537
00538 }
00539
00540
00541
00542 }
00543
00544
00545 #endif // CEYLAN_STRING_UTILS_H_
00546