diff options
author | bunnei <bunneidev@gmail.com> | 2022-02-15 20:02:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-15 20:02:23 +0100 |
commit | 910a0fa58ef5a2657fe1a476484ea235ce821082 (patch) | |
tree | 0c07b5a6c28b4674f6162559d6ed838223d40a8b /src/common | |
parent | Merge pull request #7871 from german77/svc2 (diff) | |
parent | common: fs_util: Add buffer to string view utility functions (diff) | |
download | yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.tar yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.tar.gz yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.tar.bz2 yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.tar.lz yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.tar.xz yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.tar.zst yuzu-910a0fa58ef5a2657fe1a476484ea235ce821082.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/fs/fs_util.cpp | 8 | ||||
-rw-r--r-- | src/common/fs/fs_util.h | 18 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp index 9f8671982..0068112e6 100644 --- a/src/common/fs/fs_util.cpp +++ b/src/common/fs/fs_util.cpp @@ -16,6 +16,10 @@ std::u8string BufferToU8String(std::span<const u8> buffer) { return std::u8string{buffer.begin(), std::ranges::find(buffer, u8{0})}; } +std::u8string_view BufferToU8StringView(std::span<const u8> buffer) { + return std::u8string_view{reinterpret_cast<const char8_t*>(buffer.data())}; +} + std::string ToUTF8String(std::u8string_view u8_string) { return std::string{u8_string.begin(), u8_string.end()}; } @@ -24,6 +28,10 @@ std::string BufferToUTF8String(std::span<const u8> buffer) { return std::string{buffer.begin(), std::ranges::find(buffer, u8{0})}; } +std::string_view BufferToUTF8StringView(std::span<const u8> buffer) { + return std::string_view{reinterpret_cast<const char*>(buffer.data())}; +} + 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 1ec82eb35..1620d38c9 100644 --- a/src/common/fs/fs_util.h +++ b/src/common/fs/fs_util.h @@ -38,6 +38,15 @@ concept IsChar = std::same_as<T, char>; [[nodiscard]] std::u8string BufferToU8String(std::span<const u8> buffer); /** + * Same as BufferToU8String, but returns a string view of the buffer. + * + * @param buffer Buffer of bytes + * + * @returns UTF-8 encoded std::u8string_view. + */ +[[nodiscard]] std::u8string_view BufferToU8StringView(std::span<const u8> buffer); + +/** * Converts a std::u8string or std::u8string_view to a UTF-8 encoded std::string. * * @param u8_string UTF-8 encoded u8string @@ -58,6 +67,15 @@ concept IsChar = std::same_as<T, char>; [[nodiscard]] std::string BufferToUTF8String(std::span<const u8> buffer); /** + * Same as BufferToUTF8String, but returns a string view of the buffer. + * + * @param buffer Buffer of bytes + * + * @returns UTF-8 encoded std::string_view. + */ +[[nodiscard]] std::string_view BufferToUTF8StringView(std::span<const u8> buffer); + +/** * Converts a filesystem path to a UTF-8 encoded std::string. * * @param path Filesystem path |