Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

misc/string.h

Go to the documentation of this file.
00001 #ifndef MISC_STRING_H
00002 #define MISC_STRING_H
00003 
00004 /*
00005 
00006   GLT OpenGL C++ Toolkit (LGPL)
00007   Copyright (C) 2000-2002 Nigel Stewart  
00008 
00009   Email: nigels.com@gmail.com   
00010   WWW:   http://www.nigels.com/glt/
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 */
00027 
00036 #include <glt/config.h>
00037 
00038 #ifdef GLT_WIN32
00039 #pragma warning(disable: 4786)      
00040 #endif
00041 
00042 #include <string>
00043 #include <vector>
00044 #include <iosfwd>
00045 
00046 #ifdef GLT_UNIX
00047 namespace std
00048 {
00049     typedef basic_string <wchar_t> wstring;
00050 }
00051 #endif
00052 
00057 bool isBinary(const std::string  &str);
00058 
00059 //
00060 // DOS <-> UNIX
00061 //
00062 
00067 void dos2unix(std::string  &dest,const std::string  &src);
00068 
00073 void dos2unix(std::wstring &dest,const std::wstring &src);
00074 
00079 void unix2dos(std::string  &dest,const std::string  &src);
00080 
00085 void unix2dos(std::wstring &dest,const std::wstring &src);
00086 
00087 //
00088 // string <-> stream
00089 //
00090 
00095 void readStream (std::istream &is,std::string &dest);
00096 
00101 void writeStream(std::ostream &os,const std::string &src);
00102 
00107 void readUnicodeStream (std::istream &is,std::wstring &dest);
00108 
00113 void writeUnicodeStream(std::ostream &os,const std::wstring &src);
00114 
00115 //
00116 // string <-> wstring
00117 //
00118 
00123 void string2wstring(std::wstring &dest, const std::string  &src);
00124 
00129 void wstring2string(std::string  &dest, const std::wstring &src);
00130 
00135 void utf8decode(std::wstring &dest, const std::string &src);
00136 
00137 //
00138 // string -> C/C++ source
00139 // 
00140 
00145 void bin2src(std::ostream &os, const unsigned char *buffer, const int n);
00146 
00151 void bin2src(std::ostream &os, const std::string &src);
00152 
00157 void bin2src(std::ostream &os, std::istream &is);
00158 
00159 //
00160 // string -> gcc assembler
00161 //
00162 
00167 void bin2asm(std::ostream &os, const unsigned char *buffer, const int n);
00168 
00173 void bin2asm(std::ostream &os, const std::string &src);
00174 
00179 void bin2asm(std::ostream &os, std::istream &is);
00180 
00181 //
00182 // hex conversion
00183 //
00184 
00189 unsigned int  fromHex4(unsigned char ch);
00190 
00195 unsigned char toHex4(unsigned int val);
00196 
00197 //
00198 // string <-> vector<string>
00199 //
00200 
00206 bool stringSplit(std::vector<std::string> &vec, const std::string &str, const std::string &delim);
00207 
00213 bool stringMerge(const std::vector<std::string> &vec, std::string &str, const std::string &delim);
00214 
00215 //
00216 // Adaptors for ANSI C functions
00217 //
00218 
00224 double atof(const std::string &str);
00225 
00231 int    atoi(const std::string &str);
00232 
00238 long   atol(const std::string &str);
00239 
00245 bool   atob(const std::string &str);
00246 
00257 template<class T,class I>
00258 const int atoc(const std::string &str,T (*f)(const std::string &),const std::string &match,const I &begin,const I &end)
00259 {
00260     int    n = 0;
00261     I      i = begin;
00262     size_t j = 0;
00263 
00264     while (i!=end)
00265     {
00266         j = str.find_first_of(match,j);
00267         if (j==std::string::npos)
00268             break;
00269 
00270         *i = f(str.substr(j));
00271         
00272         n++;
00273         i++;
00274 
00275         j = str.find_first_not_of(match,j);
00276         if (j==std::string::npos)
00277             break;
00278     }
00279 
00280     for (;i!=end;i++)
00281         *i = T();
00282 
00283     return n;
00284 }
00285 
00286 #endif

Generated on Tue Nov 5 11:11:05 2002 for GLT by doxygen1.2.18