string_util: Add U16StringFromBuffer

Qt's QString::toStdU16String doesn't work when compiling against the
latest libstdc++, at least when using Clang. This function effectively
does the same thing as the aforementioned one.
This commit is contained in:
lat9nq 2022-05-15 18:06:33 -04:00
parent 5808e76fae
commit ffd3afcf2f
2 changed files with 6 additions and 0 deletions

View File

@ -178,6 +178,10 @@ std::wstring UTF8ToUTF16W(const std::string& input) {
#endif #endif
std::u16string U16StringFromBuffer(const u16* input, std::size_t length) {
return std::u16string(reinterpret_cast<const char16_t*>(input), length);
}
std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) { std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) {
std::size_t len = 0; std::size_t len = 0;
while (len < buffer.length() && len < max_len && buffer[len] != '\0') { while (len < buffer.length() && len < max_len && buffer[len] != '\0') {

View File

@ -44,6 +44,8 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
#endif #endif
[[nodiscard]] std::u16string U16StringFromBuffer(const u16* input, std::size_t length);
/** /**
* Compares the string defined by the range [`begin`, `end`) to the null-terminated C-string * Compares the string defined by the range [`begin`, `end`) to the null-terminated C-string
* `other` for equality. * `other` for equality.