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
00138 CEYLAN_DLL std::string formatStringList(
00139 const std::list<std::string> & stringList,
00140 bool surroundByTicks = false, Ceylan::Uint8 indentationLevel = 1 ) ;
00141
00142
00143
00168 CEYLAN_DLL std::string formatStringList(
00169 const std::list<std::string> & stringList,
00170 TextDisplayable::TextOutputFormat targetFormat,
00171 bool surroundByTicks = false, Ceylan::Uint8 indentationLevel = 1 ) ;
00172
00173
00174
00191 CEYLAN_DLL std::string formatStringMap(
00192 const std::map<std::string, std::string> & stringMap,
00193 bool surroundByTicks = false ) ;
00194
00195
00196
00197
00198
00199
00212 CEYLAN_DLL void display( const std::string & message ) ;
00213
00214
00215
00223 CEYLAN_DLL void displayError( const std::string & errorMessage ) ;
00224
00225
00226
00232 CEYLAN_DLL StringSize countChars( const std::string & aString,
00233 char targetChar ) ;
00234
00235
00236
00243 CEYLAN_DLL std::string reverse( const std::string & source ) ;
00244
00245
00246
00284 CEYLAN_DLL char * getNonConstCharFrom( const std::string & source ) ;
00285
00286
00287
00295 CEYLAN_DLL StringSize substituteInString(
00296 std::string & targetString,
00297 const std::string & toBeReplaced,
00298 const std::string & replacement ) ;
00299
00300
00301
00310 CEYLAN_DLL std::string substituteIn(
00311 const std::string & sourceString,
00312 const std::string & toBeReplaced,
00313 const std::string & replacement ) ;
00314
00315
00316
00326 CEYLAN_DLL bool isLetter( char targetChar ) ;
00327
00328
00329
00338 CEYLAN_DLL bool isFigure( char targetChar ) ;
00339
00340
00341
00351 CEYLAN_DLL bool isAlphanumeric( char targetChar ) ;
00352
00353
00354
00365 CEYLAN_DLL bool isPunctuation( char targetChar ) ;
00366
00367
00368
00378 CEYLAN_DLL bool isWhitespace( char targetChar ) ;
00379
00380
00381
00387 CEYLAN_DLL std::string toUppercase( const std::string & text ) ;
00388
00389
00390
00397 CEYLAN_DLL std::string encodeToHTML( const std::string & message ) ;
00398
00399
00400
00412 CEYLAN_DLL std::string encodeToPhonetic( const std::string & message ) ;
00413
00414
00415
00428 CEYLAN_DLL std::string encodeToROT13( const std::string & message ) ;
00429
00430
00431
00442 CEYLAN_DLL std::string demangleSymbol( const std::string & symbol ) ;
00443
00444
00445
00455 CEYLAN_DLL std::list<std::string> split( const std::string & stringToSplit,
00456 char splittingChar ) ;
00457
00458
00459
00469
00470
00471
00472
00473
00474
00475
00485 CEYLAN_DLL std::string join( const std::list<std::string> & toJoin,
00486 const std::string & joiningString ) ;
00487
00488
00489
00506 CEYLAN_DLL std::list<std::string> splitIntoWords(
00507 const std::string & sentenceToSplit ) ;
00508
00509
00510
00523 CEYLAN_DLL std::list<std::string> splitIntoParagraphs(
00524 const std::string & textToSplit ) ;
00525
00526
00527
00532 template <typename T>
00533 std::string toString( const std::list<T> & targetList )
00534 {
00535
00536 std::list<std::string> res ;
00537
00538 for ( typename std::list<T>::const_iterator it = targetList.begin() ;
00539 it != targetList.end(); it++ )
00540 res.push_back( Ceylan::toString( *it ) ) ;
00541
00542 return "[ " + join( res, ", " ) + " ]" ;
00543
00544 }
00545
00546
00547
00554 template <typename T>
00555 void stringToObject( const std::string & source, T & object )
00556 {
00557
00558 std::istringstream iss( source ) ;
00559 iss >> object ;
00560
00561 #if CEYLAN_DEBUG_STRING_TO_OBJECT
00562
00563 if ( iss.fail() )
00564 {
00565 throw Ceylan::Exception(
00566 "Conversion error in Ceylan string utilities "
00567 "while using template stringToObject." ) ;
00568 }
00569
00570 #endif // CEYLAN_DEBUG_STRING_TO_OBJECT
00571
00572 }
00573
00574
00575
00576 }
00577
00578
00579 #endif // CEYLAN_STRING_UTILS_H_
00580