Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Ztring.h

Go to the documentation of this file.
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 Char *) const;
00099     Ztring &operator += (const Ztring &);
00100     Ztring &operator += (const Char *);
00101     Ztring &operator = (const Ztring &);
00102     Ztring &operator = (const Char *);
00103     bool operator == (const Ztring &Value) const                                {return compare(Ztring(Value))==0;};
00104     bool operator == (const Char *Value) const                                  {return compare(Ztring(Value))==0;};
00105     bool operator != (const Ztring &Value) const                                {return compare(Ztring(Value))!=0;};
00106     bool operator != (const Char *Value) const                                  {return compare(Ztring(Value))!=0;};
00107 
00108     //Conversions
00109     static Ztring ToZtring (const int8s, int radix=10);
00110     static Ztring ToZtring (const int8u, int radix=10);
00111     static Ztring ToZtring (const int16s, int radix=10);
00112     static Ztring ToZtring (const int16u, int radix=10);
00113     static Ztring ToZtring (const int32s, int radix=10);
00114     static Ztring ToZtring (const int32u, int radix=10);
00115 #if (MAXTYPE_INT >= 64)
00116     static Ztring ToZtring (const int64s, int radix=10);
00117     static Ztring ToZtring (const int64u, int radix=10);
00118 #endif
00119     static Ztring ToZtring (const float32, int decimal=3);
00120     static Ztring ToZtring (const float64, int decimal=3);
00121         /// @brief return a new char array
00122         /// @warning you MUST delete this pointer! (delete[])
00123     Char* Convert_Char() const;
00124         /// @brief Convert into Int (32 bits)
00125         /// @return the value corresponding \n
00126         ///         0 if there is a problem
00127     int32s Convert_int32s(ztring_t Options=Ztring_Rounded) const;
00128         /// @brief Convert into unsigned Int (32 bits)
00129         /// @return the value corresponding
00130         ///         0 if there is a problem
00131     int32u Convert_int32u(ztring_t Options=Ztring_Rounded) const;
00132 #if (MAXTYPE_INT >= 64)
00133         /// @brief Convert into Int (64 bits)
00134         /// @return the value corresponding \n
00135         ///         0 if there is a problem
00136     int64s Convert_int64s(ztring_t Options=Ztring_Rounded) const;
00137         /// @brief Convert into unsigned Int (64 bits)
00138         /// @return the value corresponding \n
00139         ///         0 if there is a problem
00140     int64u Convert_int64u(ztring_t Options=Ztring_Rounded) const;
00141 #endif
00142         /// @brief Convert into float
00143         /// @return the value corresponding \n
00144         ///         0 if there is a problem
00145     float32 Convert_float32(ztring_t Options=Ztring_Rounded) const; //Vers decimal
00146     float64 Convert_float64(ztring_t Options=Ztring_Rounded) const; //Vers decimal
00147 
00148     //Edition
00149         /// @brief convert into lowercase
00150     Ztring* MakeLowerCase();
00151         /// @brief convert into uppercase
00152     Ztring* MakeUpperCase();
00153         /// @brief Remove leading whitespaces from a string
00154     Ztring* TrimLeft();
00155         /// @brief Remove trailing whitespaces from a string
00156     Ztring* TrimRight();
00157         /// @brief Remove leading and trailing whitespaces from a string
00158     Ztring* Trim();
00159         /// @brief Quotes a string
00160     Ztring* Quote();
00161         /// @brief return a string between two strings
00162         /// @param Begin First string
00163         /// @param End Second string
00164         /// @param Pos Position to begin to scan string
00165         /// @param Options Options for searching \n
00166         ///                Available : Ztring_CaseSensitive
00167         /// @return The substring \n
00168         ///         "" if not found
00169     Ztring SubString (const ZENLIB_STRINGTYPE &Begin, const ZENLIB_STRINGTYPE &End, size_type Pos=0, ztring_t Options=Ztring_Nothing) const;
00170         /// @brief replace a string by another one
00171         /// @param ToFind string to find
00172         /// @param ToReplace string wich replace the string found
00173         /// @param Pos Position to begin to scan string
00174         /// @param Options Options for searching \n
00175         ///                Available : Ztring_CaseSensitive, Ztring_Recursive
00176         /// @return The substring \n
00177         ///         "" if not found
00178     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
00179 
00180 /*
00181 
00182     //Edition
00183     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
00184     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
00185     Ztring SousChaine (int Pos_Debut, int Nb_Char=-1) const; //Retourne une Chaine situe entre deux positions (pos debut puis nombre de characteres)
00186     Ztring SousChaine_Pos (int Pos_Debut, int Pos_Fin=-1) const; //Retourne une Chaine situe entre deux positions (pos debut et pos fin)
00187     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
00188     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
00189     int Compter(const Ztring &ACompter, int Options=0) const; //Compte le nombre d'occurence d'une chaine
00190     bool Comparer (const Ztring &AComparer, const Ztring &Comparateur, int Options=0) const; //Comapre une chaine avec une autre
00191 */
00192 };
00193 
00194 } //NameSpace
00195 #endif
00196 
00197 

Generated on Mon Jan 10 01:41:04 2005 for ZenLib by doxygen1.3-rc3