diff options
| author | 2023-03-19 11:10:16 -0700 | |
|---|---|---|
| committer | 2023-03-19 11:10:16 -0700 | |
| commit | 3d4c113037d8033e29277c8bf75bec9464d09009 (patch) | |
| tree | 4285a4ec350a5265e189a82d91a9874c97da36d6 /src | |
| parent | Merge pull request #9972 from liamwhite/ipc-trace (diff) | |
| parent | common: string_util: Use std::string_view for UTF16ToUTF8/UTF8ToUTF16W. (diff) | |
| download | yuzu-3d4c113037d8033e29277c8bf75bec9464d09009.tar.gz yuzu-3d4c113037d8033e29277c8bf75bec9464d09009.tar.xz yuzu-3d4c113037d8033e29277c8bf75bec9464d09009.zip | |
Merge pull request #9970 from bunnei/string-util-view
common: string_util: Use std::string_view for UTF16ToUTF8/UTF8ToUTF16W.
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 | |||
| 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 | ||
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* _ | |||
| 36 | [[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, | 36 | [[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, |
| 37 | const std::string& dest); | 37 | const std::string& dest); |
| 38 | 38 | ||
| 39 | [[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input); | 39 | [[nodiscard]] std::string UTF16ToUTF8(std::u16string_view input); |
| 40 | [[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input); | 40 | [[nodiscard]] std::u16string UTF8ToUTF16(std::string_view input); |
| 41 | 41 | ||
| 42 | #ifdef _WIN32 | 42 | #ifdef _WIN32 |
| 43 | [[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input); | 43 | [[nodiscard]] std::string UTF16ToUTF8(std::wstring_view input); |
| 44 | [[nodiscard]] std::wstring UTF8ToUTF16W(const std::string& str); | 44 | [[nodiscard]] std::wstring UTF8ToUTF16W(std::string_view str); |
| 45 | 45 | ||
| 46 | #endif | 46 | #endif |
| 47 | 47 | ||