Lines 23-28
Link Here
|
23 |
|
23 |
|
24 |
#include "StringUtil.hh" |
24 |
#include "StringUtil.hh" |
25 |
|
25 |
|
|
|
26 |
|
27 |
#include <cstring> |
28 |
#include <locale> |
26 |
#include <string> |
29 |
#include <string> |
27 |
#include <cstdio> |
30 |
#include <cstdio> |
28 |
#include <cstdlib> |
31 |
#include <cstdlib> |
Lines 37-42
Link Here
|
37 |
|
40 |
|
38 |
namespace StringUtil { |
41 |
namespace StringUtil { |
39 |
|
42 |
|
|
|
43 |
|
44 |
/* |
45 |
* structs needed for std::transform() |
46 |
* See: http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/howto.html#7 |
47 |
*/ |
48 |
struct ToUpper { |
49 |
ToUpper(std::locale const& l) : loc(l) {;} |
50 |
char operator() (char c) const { return std::toupper(c,loc); } |
51 |
private: |
52 |
std::locale const& loc; |
53 |
}; |
54 |
|
55 |
struct ToLower { |
56 |
ToLower(std::locale const& l) : loc(l) {;} |
57 |
char operator() (char c) const { return std::tolower(c,loc); } |
58 |
private: |
59 |
std::locale const& loc; |
60 |
}; |
61 |
|
62 |
|
40 |
/** |
63 |
/** |
41 |
Takes a pointer to string *s as an argument, |
64 |
Takes a pointer to string *s as an argument, |
42 |
creates a new string n, copies s to n and |
65 |
creates a new string n, copies s to n and |
Lines 160-173
Link Here
|
160 |
} |
183 |
} |
161 |
|
184 |
|
162 |
std::string toLower(const std::string &conv) { |
185 |
std::string toLower(const std::string &conv) { |
|
|
186 |
|
187 |
ToLower __tolower(std::locale::classic()); |
188 |
|
163 |
std::string ret = conv; |
189 |
std::string ret = conv; |
164 |
std::transform(ret.begin(), ret.end(), ret.begin(), tolower); |
190 |
std::transform(ret.begin(), ret.end(), ret.begin(), __tolower); |
165 |
return ret; |
191 |
return ret; |
166 |
} |
192 |
} |
167 |
|
193 |
|
168 |
std::string toUpper(const std::string &conv) { |
194 |
std::string toUpper(const std::string &conv) { |
|
|
195 |
|
196 |
ToUpper __toupper(std::locale::classic()); |
197 |
|
169 |
std::string ret = conv; |
198 |
std::string ret = conv; |
170 |
std::transform(ret.begin(), ret.end(), ret.begin(), toupper); |
199 |
std::transform(ret.begin(), ret.end(), ret.begin(), __toupper); |
171 |
return ret; |
200 |
return ret; |
172 |
} |
201 |
} |
173 |
|
202 |
|