diff options
author | bunnei <bunneidev@gmail.com> | 2023-03-19 06:42:25 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-03-19 06:42:25 +0100 |
commit | 00d401d6396b68b711b9e336aaa2fac5edb91a2d (patch) | |
tree | ca3f4e0e99f865f039989901235756ecde5535b5 /src | |
parent | Merge pull request #9966 from bunnei/bounded-polyfill (diff) | |
download | yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.gz yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.bz2 yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.lz yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.xz yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.zst yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/string_util.cpp | 14 | ||||
-rw-r--r-- | src/common/string_util.h | 8 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index e0b6180c5..feab1653d 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -125,18 +125,18 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st return result; } -std::string UTF16ToUTF8(const std::u16string& input) { +std::string UTF16ToUTF8(std::u16string_view input) { std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; - return convert.to_bytes(input); + return convert.to_bytes(input.data(), input.data() + input.size()); } -std::u16string UTF8ToUTF16(const std::string& input) { +std::u16string UTF8ToUTF16(std::string_view input) { std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; - return convert.from_bytes(input); + return convert.from_bytes(input.data(), input.data() + input.size()); } #ifdef _WIN32 -static std::wstring CPToUTF16(u32 code_page, const std::string& input) { +static std::wstring CPToUTF16(u32 code_page, std::string_view input) { const auto size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); @@ -154,7 +154,7 @@ static std::wstring CPToUTF16(u32 code_page, const std::string& input) { return output; } -std::string UTF16ToUTF8(const std::wstring& input) { +std::string UTF16ToUTF8(std::wstring_view input) { const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); if (size == 0) { @@ -172,7 +172,7 @@ std::string UTF16ToUTF8(const std::wstring& input) { return output; } -std::wstring UTF8ToUTF16W(const std::string& input) { +std::wstring UTF8ToUTF16W(std::string_view input) { return CPToUTF16(CP_UTF8, input); } diff --git a/src/common/string_util.h b/src/common/string_util.h index f8aecc875..c351f1a0c 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -36,12 +36,12 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ [[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); -[[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input); -[[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input); +[[nodiscard]] std::string UTF16ToUTF8(std::u16string_view input); +[[nodiscard]] std::u16string UTF8ToUTF16(std::string_view input); #ifdef _WIN32 -[[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input); -[[nodiscard]] std::wstring UTF8ToUTF16W(const std::string& str); +[[nodiscard]] std::string UTF16ToUTF8(std::wstring_view input); +[[nodiscard]] std::wstring UTF8ToUTF16W(std::string_view str); #endif |