00001 // ZenLib::Ztring - std::string is better 00002 // Copyright (C) 2002-2004 Jérôme Martinez, Zen@MediaArea.net 00003 // 00004 // This software is provided 'as-is', without any express or implied 00005 // warranty. In no event will the authors be held liable for any damages 00006 // arising from the use of this software. 00007 // 00008 // Permission is granted to anyone to use this software for any purpose, 00009 // including commercial applications, and to alter it and redistribute it 00010 // freely, subject to the following restrictions: 00011 // 00012 // 1. The origin of this software must not be misrepresented; you must not 00013 // claim that you wrote the original software. If you use this software 00014 // in a product, an acknowledgment in the product documentation would be 00015 // appreciated but is not required. 00016 // 2. Altered source versions must be plainly marked as such, and must not be 00017 // misrepresented as being the original software. 00018 // 3. This notice may not be removed or altered from any source distribution. 00019 // 00020 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00021 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00022 // String 00023 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 // 00025 // Version 0.1.0 00026 // ------------- 00027 // Gestion poussées des chaines de caractères 00028 // 00029 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00030 // 00031 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00032 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00033 00034 //--------------------------------------------------------------------------- 00035 #ifndef ZenLib_ZtringH 00036 #define ZenLib_ZtringH 00037 //--------------------------------------------------------------------------- 00038 00039 //--------------------------------------------------------------------------- 00040 #include <ZenLib/Conf.h> 00041 #include <string> 00042 //--------------------------------------------------------------------------- 00043 00044 //--------------------------------------------------------------------------- 00045 #ifdef _UNICODE 00046 #define ZENLIB_STRINGTYPE std::wstring 00047 #define ZENLIB_STRINGTYPE_SHORT wstring 00048 #else 00049 #define ZENLIB_STRINGTYPE std::string 00050 #define ZENLIB_STRINGTYPE_SHORT string 00051 #endif 00052 //--------------------------------------------------------------------------- 00053 00054 namespace ZenLib 00055 { 00056 00057 //--------------------------------------------------------------------------- 00058 /// @brief Options for Ztring methods 00059 enum ztring_t 00060 { 00061 Ztring_Nothing, 00062 Ztring_Rounded = 1, ///< if >.5, upper, else lower 00063 Ztring_CaseSensitive = 2, ///< Case sensitive ("A" and "a" are different) 00064 Ztring_AddLastItem = 4, ///< if Begin is found and End is not found, return between Begin and end of string 00065 Ztring_Recursive = 8 ///< Do all strings 00066 }; 00067 00068 //--------------------------------------------------------------------------- 00069 00070 //*************************************************************************** 00071 /// @brief String manipulation (based on std::string) 00072 /// @version 0.0.1 00073 //*************************************************************************** 00074 00075 using ZENLIB_STRINGTYPE; 00076 class Ztring : public ZENLIB_STRINGTYPE //for details about undocumented methods see http://www.sgi.com/tech/stl/basic_string.html 00077 { 00078 public : 00079 //Gestion de la classe 00080 Ztring () : ZENLIB_STRINGTYPE_SHORT(){}; 00081 Ztring (const ZENLIB_STRINGTYPE& s, size_type pos=0, size_type n=npos) : ZENLIB_STRINGTYPE_SHORT(s.c_str(), pos, npos){}; 00082 Ztring (const ZENLIB_STRINGTYPE* s, size_type pos=0, size_type n=npos) : ZENLIB_STRINGTYPE_SHORT(*s, pos, npos){}; 00083 Ztring (const Char *s) : ZENLIB_STRINGTYPE_SHORT(s){}; 00084 Ztring (const Char *s, size_type n) : ZENLIB_STRINGTYPE_SHORT(s, n){}; 00085 Ztring (size_type n, const Char s) : ZENLIB_STRINGTYPE_SHORT(n, s){}; 00086 Ztring (const ints); 00087 Ztring (const intu); 00088 #if (MAXTYPE_INT >= 64 && UINT_MAX == 0xfffffffful) //We are not on 64 bit platform 00089 Ztring (const int64s); 00090 Ztring (const int64u); 00091 #endif 00092 Ztring (const float32); 00093 Ztring (const float64); 00094 00095 00096 //Operators 00097 Ztring operator + (const Ztring &) const; 00098 Ztring &operator += (const Ztring &); 00099 Ztring &operator = (const Ztring &); 00100 bool operator == (const Ztring &Value) const {return compare(Ztring(Value))==0;}; 00101 bool operator != (const Ztring &Value) const {return compare(Ztring(Value))!=0;}; 00102 00103 //Conversions 00104 static Ztring ToZtring (const int8s, int radix=10); 00105 static Ztring ToZtring (const int8u, int radix=10); 00106 static Ztring ToZtring (const int16s, int radix=10); 00107 static Ztring ToZtring (const int16u, int radix=10); 00108 static Ztring ToZtring (const int32s, int radix=10); 00109 static Ztring ToZtring (const int32u, int radix=10); 00110 #if (MAXTYPE_INT >= 64) 00111 static Ztring ToZtring (const int64s, int radix=10); 00112 static Ztring ToZtring (const int64u, int radix=10); 00113 #endif 00114 static Ztring ToZtring (const float32, int decimal=3); 00115 static Ztring ToZtring (const float64, int decimal=3); 00116 /// @brief return a new char array 00117 /// @warning you MUST delete this pointer! (delete[]) 00118 Char* Convert_Char() const; 00119 /// @brief Convert into Int (32 bits) 00120 /// @return the value corresponding \n 00121 /// 0 if there is a problem 00122 int32s Convert_int32s(ztring_t Options=Ztring_Rounded) const; 00123 /// @brief Convert into unsigned Int (32 bits) 00124 /// @return the value corresponding 00125 /// 0 if there is a problem 00126 int32u Convert_int32u(ztring_t Options=Ztring_Rounded) const; 00127 #if (MAXTYPE_INT >= 64) 00128 /// @brief Convert into Int (64 bits) 00129 /// @return the value corresponding \n 00130 /// 0 if there is a problem 00131 int64s Convert_int64s(ztring_t Options=Ztring_Rounded) const; 00132 /// @brief Convert into unsigned Int (64 bits) 00133 /// @return the value corresponding \n 00134 /// 0 if there is a problem 00135 int64u Convert_int64u(ztring_t Options=Ztring_Rounded) const; 00136 #endif 00137 /// @brief Convert into float 00138 /// @return the value corresponding \n 00139 /// 0 if there is a problem 00140 float32 Convert_float32(ztring_t Options=Ztring_Rounded) const; //Vers decimal 00141 float64 Convert_float64(ztring_t Options=Ztring_Rounded) const; //Vers decimal 00142 00143 //Edition 00144 /// @brief convert into lowercase 00145 Ztring* MakeLowerCase(); 00146 /// @brief convert into uppercase 00147 Ztring* MakeUpperCase(); 00148 /// @brief Remove leading whitespaces from a string 00149 Ztring* TrimLeft(); 00150 /// @brief Remove trailing whitespaces from a string 00151 Ztring* TrimRight(); 00152 /// @brief Remove leading and trailing whitespaces from a string 00153 Ztring* Trim(); 00154 /// @brief Quotes a string 00155 Ztring* Quote(); 00156 /// @brief return a string between two strings 00157 /// @param Begin First string 00158 /// @param End Second string 00159 /// @param Pos Position to begin to scan string 00160 /// @param Options Options for searching \n 00161 /// Available : Ztring_CaseSensitive 00162 /// @return The substring \n 00163 /// "" if not found 00164 Ztring SubString (const ZENLIB_STRINGTYPE &Begin, const ZENLIB_STRINGTYPE &End, size_type Pos=0, ztring_t Options=Ztring_Nothing) const; 00165 /// @brief replace a string by another one 00166 /// @param ToFind string to find 00167 /// @param ToReplace string wich replace the string found 00168 /// @param Pos Position to begin to scan string 00169 /// @param Options Options for searching \n 00170 /// Available : Ztring_CaseSensitive, Ztring_Recursive 00171 /// @return The substring \n 00172 /// "" if not found 00173 int FindAndReplace (const ZENLIB_STRINGTYPE &ToFind, const ZENLIB_STRINGTYPE &ReplaceBy, size_type Pos=0, ztring_t Options=Ztring_Nothing); //Remplace une chaine par une autre 00174 00175 /* 00176 00177 //Edition 00178 int Rechercher (const Ztring &Trouver, int Pos_Debut=0, int Pos_Fin=-1, int Options=0) const; //Retourne la position d'une chaine de caractère. Sens inverse possible, -1 si jusqu'a la fin 00179 Ztring RechercherEntre (const Ztring &Debut, const Ztring &Fin, int Pos_Debut=0, int Pos_Fin=-1, int Options=0) const; //Retourne une Chaine situe entre deux chaines 00180 Ztring SousChaine (int Pos_Debut, int Nb_Char=-1) const; //Retourne une Chaine situe entre deux positions (pos debut puis nombre de characteres) 00181 Ztring SousChaine_Pos (int Pos_Debut, int Pos_Fin=-1) const; //Retourne une Chaine situe entre deux positions (pos debut et pos fin) 00182 int Remplacer (const Ztring &Trouver, const Ztring &RemplacerPar, int Pos_Debut=0, int Pos_Fin=-1, int Options=0); //Remplace une chaine par une autre 00183 Ztring Reformater_Sortie (const Ztring &Trouver, const Ztring &RemplacerPar, int Pos_Debut=0, int Pos_Fin=-1, int Options=0); //Remplace une chaine par une autre 00184 int Compter(const Ztring &ACompter, int Options=0) const; //Compte le nombre d'occurence d'une chaine 00185 bool Comparer (const Ztring &AComparer, const Ztring &Comparateur, int Options=0) const; //Comapre une chaine avec une autre 00186 */ 00187 }; 00188 00189 } //NameSpace 00190 #endif 00191 00192