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

Ztring.h

Go to the documentation of this file.
00001 // ZenLib::Ztring - std::string is better
00002 // Copyright (C) 2002-2003 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.0.1
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/Utils.h>
00041 #ifdef __BORLANDC__ //Warnings in Borland
00042 #pragma warn -8059  //
00043 #endif              //
00044 #include <string>
00045 #ifdef __BORLANDC__ //Warnings in Borland
00046 #pragma warn .8059  //
00047 #endif              //
00048 //---------------------------------------------------------------------------
00049 
00050 namespace ZenLib
00051 {
00052 
00053 //---------------------------------------------------------------------------
00054 /// @brief Options for Ztring methods
00055 enum ztring_t
00056 {
00057     Ztring_Nothing,
00058     Ztring_Rounded              = 1,            ///< if >.5, upper, else lower
00059     Ztring_CaseSensitive        = 2,            ///< Case sensitive ("A" and "a" are different)
00060     Ztring_AddLastItem          = 4,            ///< if Begin is found and End is not found, return between Begin and end of string
00061     Ztring_Recursive            = 8             ///< Do all strings
00062 };
00063 
00064 //---------------------------------------------------------------------------
00065 
00066 //***************************************************************************
00067 /// @brief String manipulation (based on std::string)
00068 /// @version 0.0.1
00069 //***************************************************************************
00070 
00071 using std::string;
00072 class Ztring : public std::string  //for details about undocumented methods see http://www.sgi.com/tech/stl/basic_string.html
00073 {
00074 public :
00075     //Gestion de la classe
00076     Ztring ()                                                           : string(){};
00077     Ztring (const std::string& s, size_type pos=0, size_type n=npos)    : string(s.c_str(), pos, npos){};
00078     Ztring (const std::string* s, size_type pos=0, size_type n=npos)    : string(*s, pos, npos){};
00079     Ztring (const char *s)                                              : string(s){};
00080     Ztring (const char *s, size_type n)                                 : string(s, n){};
00081     Ztring (const char s)                                               : string(1, s){};
00082     Ztring (size_type n, const char s)                                  : string(n, s){};
00083 
00084     Ztring (const int32, size_type radix=10);
00085     Ztring (const uint32, size_type radix=10);
00086 #if (MAXTYPES >= 64)
00087     Ztring (const int64, size_type radix=10);
00088     Ztring (const uint64, size_type radix=10);
00089 #endif
00090     Ztring (const float);
00091     Ztring (const double);
00092 
00093     //Operators
00094     friend Ztring operator + (const char*, const Ztring &);
00095     Ztring operator + (const Ztring &) const;
00096     Ztring &operator += (const char*);
00097     Ztring &operator += (const Ztring &);
00098     char &operator () (size_type index)                                 {return operator [] (index);};
00099 
00100     //Conversions
00101         /// @deprecated Use c_str()
00102     const char* Char() const                                            {return c_str();};
00103         /// @brief return a new char array
00104         /// @warning you MUST delete this pointer! (delete[])
00105     char* ToChar() const;
00106         /// @brief Convert into Int (32 bits)
00107         /// @return the value corresponding \n
00108         ///         0 if there is a problem
00109     int32 Convert_int32(ztring_t Options=Ztring_Rounded) const;
00110         /// @brief Convert into unsigned Int (32 bits)
00111         /// @return the value corresponding
00112         ///         0 if there is a problem
00113     uint32 Convert_uint32(ztring_t Options=Ztring_Rounded) const;
00114 #if (MAXTYPES >= 64)
00115         /// @brief Convert into Int (64 bits)
00116         /// @return the value corresponding \n
00117         ///         0 if there is a problem
00118     int64 Convert_int64(ztring_t Options=Ztring_Rounded) const;
00119         /// @brief Convert into unsigned Int (64 bits)
00120         /// @return the value corresponding \n
00121         ///         0 if there is a problem
00122     uint64 Convert_uint64(ztring_t Options=Ztring_Rounded) const;
00123 #endif
00124         /// @brief Convert into float
00125         /// @return the value corresponding \n
00126         ///         0 if there is a problem
00127     float Convert_float(ztring_t Options=Ztring_Rounded) const; //Vers decimal
00128 
00129     //Edition
00130         /// @brief convert into lowercase
00131     Ztring* MakeLowerCase();
00132         /// @brief convert into uppercase
00133     Ztring* MakeUpperCase();
00134         /// @brief Remove leading whitespaces from a string
00135     Ztring* TrimLeft();
00136         /// @brief Remove trailing whitespaces from a string
00137     Ztring* TrimRight();
00138         /// @brief Remove leading and trailing whitespaces from a string
00139     Ztring* Trim();
00140         /// @brief Quotes a string
00141     Ztring* Quote();
00142         /// @brief return a string between two strings
00143         /// @param Begin First string
00144         /// @param End Second string
00145         /// @param Pos Position to begin to scan string
00146         /// @param Options Options for searching \n
00147         ///                Available : Ztring_CaseSensitive
00148         /// @return The substring \n
00149         ///         "" if not found
00150     Ztring SubString (const std::string &Begin, const std::string &End, int Pos=0, ztring_t Options=Ztring_Nothing) const;
00151         /// @brief replace a string by another one
00152         /// @param ToFind string to find
00153         /// @param ToReplace string wich replace the string found
00154         /// @param Pos Position to begin to scan string
00155         /// @param Options Options for searching \n
00156         ///                Available : Ztring_CaseSensitive, Ztring_Recursive
00157         /// @return The substring \n
00158         ///         "" if not found
00159     int FindAndReplace (const std::string &ToFind, const std::string &ReplaceBy, size_t Pos=0, ztring_t Options=Ztring_Nothing); //Remplace une chaine par une autre
00160 
00161 /*
00162 
00163     //Edition
00164     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
00165     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
00166     Ztring SousChaine (int Pos_Debut, int Nb_Char=-1) const; //Retourne une Chaine situe entre deux positions (pos debut puis nombre de characteres)
00167     Ztring SousChaine_Pos (int Pos_Debut, int Pos_Fin=-1) const; //Retourne une Chaine situe entre deux positions (pos debut et pos fin)
00168     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
00169     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
00170     int Compter(const Ztring &ACompter, int Options=0) const; //Compte le nombre d'occurence d'une chaine
00171     bool Comparer (const Ztring &AComparer, const Ztring &Comparateur, int Options=0) const; //Comapre une chaine avec une autre
00172 
00173     //Traitements
00174     Ztring *ToMin (); //Converti en minuscules
00175     Ztring *ToMaj (); //Converti en majuscules
00176 */
00177 };
00178 
00179 } //NameSpace
00180 #endif
00181 
00182 

Generated on Wed Jun 18 00:34:51 2003 for ZenLib by doxygen1.3-rc3