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