OLD | NEW |
1 #ifndef UTILS_H | 1 #ifndef UTILS_H |
2 #define UTILS_H | 2 #define UTILS_H |
3 | 3 |
| 4 #include <algorithm> |
| 5 #include <locale> |
| 6 #include <functional> |
4 #include <string> | 7 #include <string> |
5 | 8 |
6 std::string ToUtf8String(std::wstring str); | 9 std::string ToUtf8String(const std::wstring& str); |
| 10 std::wstring ToUtf16String(const std::string& str); |
| 11 std::wstring GetDllDir(); |
7 std::wstring GetAppDataPath(); | 12 std::wstring GetAppDataPath(); |
8 | 13 |
| 14 template<class T> |
| 15 T TrimString(T text) |
| 16 { |
| 17 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st
dstring |
| 18 T trimmed(text); |
| 19 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_
type>, std::placeholders::_1, std::locale::classic()); |
| 20 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st
d::not1(isspace))); |
| 21 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace
)).base(), trimmed.end()); |
| 22 return trimmed; |
| 23 } |
| 24 |
9 #endif // UTILS_H | 25 #endif // UTILS_H |
OLD | NEW |