00001 #ifndef MISC_STRING_H
00002 #define MISC_STRING_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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
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
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
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
00183
00184
00189 unsigned int fromHex4(unsigned char ch);
00190
00195 unsigned char toHex4(unsigned int val);
00196
00197
00198
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
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