diff options
| -rw-r--r-- | src/common/string_util.cpp | 5 | ||||
| -rw-r--r-- | src/common/string_util.h | 1 | ||||
| -rw-r--r-- | src/core/debugger/gdbstub.cpp | 17 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index feab1653d..4c7aba3f5 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -135,6 +135,11 @@ std::u16string UTF8ToUTF16(std::string_view input) { | |||
| 135 | return convert.from_bytes(input.data(), input.data() + input.size()); | 135 | return convert.from_bytes(input.data(), input.data() + input.size()); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | std::u32string UTF8ToUTF32(std::string_view input) { | ||
| 139 | std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert; | ||
| 140 | return convert.from_bytes(input.data(), input.data() + input.size()); | ||
| 141 | } | ||
| 142 | |||
| 138 | #ifdef _WIN32 | 143 | #ifdef _WIN32 |
| 139 | static std::wstring CPToUTF16(u32 code_page, std::string_view input) { | 144 | static std::wstring CPToUTF16(u32 code_page, std::string_view input) { |
| 140 | const auto size = | 145 | const auto size = |
diff --git a/src/common/string_util.h b/src/common/string_util.h index c351f1a0c..9da1ca4e9 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -38,6 +38,7 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ | |||
| 38 | 38 | ||
| 39 | [[nodiscard]] std::string UTF16ToUTF8(std::u16string_view input); | 39 | [[nodiscard]] std::string UTF16ToUTF8(std::u16string_view input); |
| 40 | [[nodiscard]] std::u16string UTF8ToUTF16(std::string_view input); | 40 | [[nodiscard]] std::u16string UTF8ToUTF16(std::string_view input); |
| 41 | [[nodiscard]] std::u32string UTF8ToUTF32(std::string_view input); | ||
| 41 | 42 | ||
| 42 | #ifdef _WIN32 | 43 | #ifdef _WIN32 |
| 43 | [[nodiscard]] std::string UTF16ToUTF8(std::wstring_view input); | 44 | [[nodiscard]] std::string UTF16ToUTF8(std::wstring_view input); |
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp index e55831f27..82964f0a1 100644 --- a/src/core/debugger/gdbstub.cpp +++ b/src/core/debugger/gdbstub.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <atomic> | 4 | #include <atomic> |
| 5 | #include <codecvt> | ||
| 6 | #include <locale> | ||
| 5 | #include <numeric> | 7 | #include <numeric> |
| 6 | #include <optional> | 8 | #include <optional> |
| 7 | #include <thread> | 9 | #include <thread> |
| @@ -12,6 +14,7 @@ | |||
| 12 | #include "common/logging/log.h" | 14 | #include "common/logging/log.h" |
| 13 | #include "common/scope_exit.h" | 15 | #include "common/scope_exit.h" |
| 14 | #include "common/settings.h" | 16 | #include "common/settings.h" |
| 17 | #include "common/string_util.h" | ||
| 15 | #include "core/arm/arm_interface.h" | 18 | #include "core/arm/arm_interface.h" |
| 16 | #include "core/core.h" | 19 | #include "core/core.h" |
| 17 | #include "core/debugger/gdbstub.h" | 20 | #include "core/debugger/gdbstub.h" |
| @@ -68,10 +71,16 @@ static std::string EscapeGDB(std::string_view data) { | |||
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | static std::string EscapeXML(std::string_view data) { | 73 | static std::string EscapeXML(std::string_view data) { |
| 74 | std::u32string converted = U"[Encoding error]"; | ||
| 75 | try { | ||
| 76 | converted = Common::UTF8ToUTF32(data); | ||
| 77 | } catch (std::range_error&) { | ||
| 78 | } | ||
| 79 | |||
| 71 | std::string escaped; | 80 | std::string escaped; |
| 72 | escaped.reserve(data.size()); | 81 | escaped.reserve(data.size()); |
| 73 | 82 | ||
| 74 | for (char c : data) { | 83 | for (char32_t c : converted) { |
| 75 | switch (c) { | 84 | switch (c) { |
| 76 | case '&': | 85 | case '&': |
| 77 | escaped += "&"; | 86 | escaped += "&"; |
| @@ -86,7 +95,11 @@ static std::string EscapeXML(std::string_view data) { | |||
| 86 | escaped += ">"; | 95 | escaped += ">"; |
| 87 | break; | 96 | break; |
| 88 | default: | 97 | default: |
| 89 | escaped += c; | 98 | if (c > 0x7f) { |
| 99 | escaped += fmt::format("&#{};", static_cast<u32>(c)); | ||
| 100 | } else { | ||
| 101 | escaped += static_cast<char>(c); | ||
| 102 | } | ||
| 90 | break; | 103 | break; |
| 91 | } | 104 | } |
| 92 | } | 105 | } |