From fd70c224d1f14b20d64adde40d86e5e4947f7b43 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Wed, 28 Jul 2021 02:05:46 +0200 Subject: [PATCH] early-access version 1934 --- README.md | 2 +- src/common/fs/fs_util.cpp | 4 ++++ src/common/fs/fs_util.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64acf9a05..0932b100f 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1933. +This is the source code for early-access 1934. ## Legal Notice diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp index 357cf5855..9f8671982 100755 --- a/src/common/fs/fs_util.cpp +++ b/src/common/fs/fs_util.cpp @@ -20,6 +20,10 @@ std::string ToUTF8String(std::u8string_view u8_string) { return std::string{u8_string.begin(), u8_string.end()}; } +std::string BufferToUTF8String(std::span buffer) { + return std::string{buffer.begin(), std::ranges::find(buffer, u8{0})}; +} + std::string PathToUTF8String(const std::filesystem::path& path) { return ToUTF8String(path.u8string()); } diff --git a/src/common/fs/fs_util.h b/src/common/fs/fs_util.h index ec9950ee7..1ec82eb35 100755 --- a/src/common/fs/fs_util.h +++ b/src/common/fs/fs_util.h @@ -46,6 +46,17 @@ concept IsChar = std::same_as; */ [[nodiscard]] std::string ToUTF8String(std::u8string_view u8_string); +/** + * Converts a buffer of bytes to a UTF8-encoded std::string. + * This converts from the start of the buffer until the first encountered null-terminator. + * If no null-terminator is found, this converts the entire buffer instead. + * + * @param buffer Buffer of bytes + * + * @returns UTF-8 encoded std::string. + */ +[[nodiscard]] std::string BufferToUTF8String(std::span buffer); + /** * Converts a filesystem path to a UTF-8 encoded std::string. *