diff options
Diffstat (limited to 'src/common/string_util.h')
-rw-r--r-- | src/common/string_util.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/common/string_util.h b/src/common/string_util.h index a41ccc691..7d75691b1 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -63,7 +63,7 @@ template <typename N> static bool TryParse(const std::string &str, N *const output) { std::istringstream iss(str); - + N tmp = 0; if (iss >> tmp) { @@ -89,20 +89,22 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st std::string UriDecode(const std::string & sSrc); std::string UriEncode(const std::string & sSrc); +std::string UTF16ToUTF8(const std::u16string& input); +std::u16string UTF8ToUTF16(const std::string& input); + std::string CP1252ToUTF8(const std::string& str); std::string SHIFTJISToUTF8(const std::string& str); -std::string UTF16ToUTF8(const std::wstring& str); #ifdef _WIN32 -std::wstring UTF8ToUTF16(const std::string& str); +std::wstring UTF8ToUTF16W(const std::string& str); #ifdef _UNICODE inline std::string TStrToUTF8(const std::wstring& str) { return UTF16ToUTF8(str); } inline std::wstring UTF8ToTStr(const std::string& str) -{ return UTF8ToUTF16(str); } +{ return UTF8ToUTF16W(str); } #else inline std::string TStrToUTF8(const std::string& str) { return str; } @@ -113,4 +115,19 @@ inline std::string UTF8ToTStr(const std::string& str) #endif +/** + * Compares the string defined by the range [`begin`, `end`) to the null-terminated C-string + * `other` for equality. + */ +template <typename InIt> +bool ComparePartialString(InIt begin, InIt end, const char* other) { + for (; begin != end && *other != '\0'; ++begin, ++other) { + if (*begin != *other) { + return false; + } + } + // Only return true if both strings finished at the same point + return (begin == end) == (*other == '\0'); +} + } |