diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/bounded_threadsafe_queue.h | 5 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 14 | ||||
| -rw-r--r-- | src/common/string_util.h | 8 |
3 files changed, 14 insertions, 13 deletions
diff --git a/src/common/bounded_threadsafe_queue.h b/src/common/bounded_threadsafe_queue.h index 21217801e..14e887c70 100644 --- a/src/common/bounded_threadsafe_queue.h +++ b/src/common/bounded_threadsafe_queue.h | |||
| @@ -9,10 +9,11 @@ | |||
| 9 | #include <memory> | 9 | #include <memory> |
| 10 | #include <mutex> | 10 | #include <mutex> |
| 11 | #include <new> | 11 | #include <new> |
| 12 | #include <stop_token> | ||
| 13 | #include <type_traits> | 12 | #include <type_traits> |
| 14 | #include <utility> | 13 | #include <utility> |
| 15 | 14 | ||
| 15 | #include "common/polyfill_thread.h" | ||
| 16 | |||
| 16 | namespace Common { | 17 | namespace Common { |
| 17 | 18 | ||
| 18 | #if defined(__cpp_lib_hardware_interference_size) | 19 | #if defined(__cpp_lib_hardware_interference_size) |
| @@ -78,7 +79,7 @@ public: | |||
| 78 | auto& slot = slots[idx(tail)]; | 79 | auto& slot = slots[idx(tail)]; |
| 79 | if (!slot.turn.test()) { | 80 | if (!slot.turn.test()) { |
| 80 | std::unique_lock lock{cv_mutex}; | 81 | std::unique_lock lock{cv_mutex}; |
| 81 | cv.wait(lock, stop, [&slot] { return slot.turn.test(); }); | 82 | Common::CondvarWait(cv, lock, stop, [&slot] { return slot.turn.test(); }); |
| 82 | } | 83 | } |
| 83 | v = slot.move(); | 84 | v = slot.move(); |
| 84 | slot.destroy(); | 85 | slot.destroy(); |
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 | ||