# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

ucstring.h

Go to the documentation of this file.
00001 
00008 /* Copyright, 2000 Nevrax Ltd.
00009  *
00010  * This file is part of NEVRAX NEL.
00011  * NEVRAX NEL is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2, or (at your option)
00014  * any later version.
00015 
00016  * NEVRAX NEL is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00019  * General Public License for more details.
00020 
00021  * You should have received a copy of the GNU General Public License
00022  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00023  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00024  * MA 02111-1307, USA.
00025  */
00026 
00027 #ifndef NL_UCSTRING_H
00028 #define NL_UCSTRING_H
00029 
00030 #include "nel/misc/types_nl.h"
00031 
00032 #include <string>
00033 
00039 typedef std::basic_string<ucchar> ucstringbase;
00040 
00041 class ucstring : public ucstringbase
00042 {
00043 public:
00044 
00045         ucstring () {}
00046 
00047         ucstring (const ucstringbase &str) : ucstringbase (str) {}
00048 
00049         ucstring (const std::string &str) : ucstringbase ()
00050         {
00051                 *this=str;
00052         }
00053 
00054         ucstring &operator= (ucchar c)
00055         {
00056                 resize (1);
00057                 operator[](0) = c;
00058                 return *this;
00059         }
00060 
00061         ucstring &operator= (const char *str)
00062         {
00063                 resize (strlen (str));
00064                 for (sint i = 0; i < (sint) strlen (str); i++)
00065                 {
00066                         operator[](i) = str[i];
00067                 }
00068                 return *this;
00069         }
00070 
00071         ucstring &operator= (const std::string &str)
00072         {
00073                 resize (str.size ());
00074                 for (sint i = 0; i < (sint) str.size (); i++)
00075                 {
00076                         operator[](i) = str[i];
00077                 }
00078                 return *this;
00079         }
00080 
00081         ucstring &operator= (const ucstringbase &str)
00082         {
00083                 ucstringbase::operator =(str);
00084                 return *this;
00085         }
00086 
00087         ucstring &operator+= (ucchar c)
00088         {
00089                 resize (size() + 1);
00090                 operator[](size()-1) = c;
00091                 return *this;
00092         }
00093 
00094         ucstring &operator+= (const char *str)
00095         {
00096                 sint s = size();
00097                 resize (s + strlen(str));
00098                 for (sint i = 0; i < (sint) strlen(str); i++)
00099                 {
00100                         operator[](s+i) = str[i];
00101                 }
00102                 return *this;
00103         }
00104 
00105         ucstring &operator+= (const std::string &str)
00106         {
00107                 sint s = size();
00108                 resize (s + str.size());
00109                 for (sint i = 0; i < (sint) str.size(); i++)
00110                 {
00111                         operator[](s+i) = str[i];
00112                 }
00113                 return *this;
00114         }
00115 
00116         ucstring &operator+= (const ucstringbase &str)
00117         {
00118                 ucstringbase::operator +=(str);
00119                 return *this;
00120         }
00121 
00122 
00124         void toString (std::string &str) const
00125         {
00126                 str.resize (size ());
00127                 for (sint i = 0; i < (sint) str.size (); i++)
00128                 {
00129                         str[i] = (char) operator[](i);
00130                 }
00131         }
00132 
00134         std::string toString () const
00135         {
00136                 std::string str;
00137                 toString(str);
00138                 return str;
00139         }
00140 
00141 };
00142 
00143 inline ucstring operator+(const ucstringbase &ucstr, ucchar c)
00144 {
00145         ucstring        ret;
00146         ret= ucstr;
00147         ret+= c;
00148         return ret;
00149 }
00150 
00151 inline ucstring operator+(const ucstringbase &ucstr, const char *c)
00152 {
00153         ucstring        ret;
00154         ret= ucstr;
00155         ret+= c;
00156         return ret;
00157 }
00158 
00159 inline ucstring operator+(const ucstringbase &ucstr, const std::string &c)
00160 {
00161         ucstring        ret;
00162         ret= ucstr;
00163         ret+= c;
00164         return ret;
00165 }
00166 
00167 inline ucstring operator+(ucchar c, const ucstringbase &ucstr)
00168 {
00169         ucstring        ret;
00170         ret= c;
00171         ret += ucstr;
00172         return ret;
00173 }
00174 
00175 inline ucstring operator+(const char *c, const ucstringbase &ucstr)
00176 {
00177         ucstring        ret;
00178         ret= c;
00179         ret += ucstr;
00180         return ret;
00181 }
00182 
00183 inline ucstring operator+(const std::string &c, const ucstringbase &ucstr)
00184 {
00185         ucstring        ret;
00186         ret= c;
00187         ret += ucstr;
00188         return ret;
00189 }
00190 
00191 #endif // NL_UCSTRING_H