diff options
| author | 2023-03-18 22:42:25 -0700 | |
|---|---|---|
| committer | 2023-03-18 22:42:25 -0700 | |
| commit | 00d401d6396b68b711b9e336aaa2fac5edb91a2d (patch) | |
| tree | ca3f4e0e99f865f039989901235756ecde5535b5 /src/common/string_util.cpp | |
| parent | Merge pull request #9966 from bunnei/bounded-polyfill (diff) | |
| download | yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.gz yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.tar.xz yuzu-00d401d6396b68b711b9e336aaa2fac5edb91a2d.zip | |
common: string_util: Use std::string_view for UTF16ToUTF8/UTF8ToUTF16W.
Diffstat (limited to 'src/common/string_util.cpp')
| -rw-r--r-- | src/common/string_util.cpp | 14 |
1 files changed, 7 insertions, 7 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 | |||
| 125 | return result; | 125 | return result; |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | std::string UTF16ToUTF8(const std::u16string& input) { | 128 | std::string UTF16ToUTF8(std::u16string_view input) { |
| 129 | std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; | 129 | std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; |
| 130 | return convert.to_bytes(input); | 130 | return convert.to_bytes(input.data(), input.data() + input.size()); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | std::u16string UTF8ToUTF16(const std::string& input) { | 133 | std::u16string UTF8ToUTF16(std::string_view input) { |
| 134 | std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; | 134 | std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; |
| 135 | return convert.from_bytes(input); | 135 | return convert.from_bytes(input.data(), input.data() + input.size()); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | #ifdef _WIN32 | 138 | #ifdef _WIN32 |
| 139 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) { | 139 | static std::wstring CPToUTF16(u32 code_page, std::string_view input) { |
| 140 | const auto size = | 140 | const auto size = |
| 141 | MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); | 141 | MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); |
| 142 | 142 | ||
| @@ -154,7 +154,7 @@ static std::wstring CPToUTF16(u32 code_page, const std::string& input) { | |||
| 154 | return output; | 154 | return output; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | std::string UTF16ToUTF8(const std::wstring& input) { | 157 | std::string UTF16ToUTF8(std::wstring_view input) { |
| 158 | const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), | 158 | const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), |
| 159 | nullptr, 0, nullptr, nullptr); | 159 | nullptr, 0, nullptr, nullptr); |
| 160 | if (size == 0) { | 160 | if (size == 0) { |
| @@ -172,7 +172,7 @@ std::string UTF16ToUTF8(const std::wstring& input) { | |||
| 172 | return output; | 172 | return output; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | std::wstring UTF8ToUTF16W(const std::string& input) { | 175 | std::wstring UTF8ToUTF16W(std::string_view input) { |
| 176 | return CPToUTF16(CP_UTF8, input); | 176 | return CPToUTF16(CP_UTF8, input); |
| 177 | } | 177 | } |
| 178 | 178 | ||