diff options
author | Mai M <mathew1800@gmail.com> | 2021-06-02 00:28:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-02 00:28:34 -0400 |
commit | 50866199a4f76db501f692112ddfe142679ad3bb (patch) | |
tree | 24a040c1117135d965e9f17aefa37a6cdd9d3bc7 /src/common/fs/fs_util.h | |
parent | 91f559a71f3081c0879c346002e687d83d333673 (diff) | |
parent | dba7bcd489b9802c3d25e3e8183ef7991af301b8 (diff) |
Merge pull request #6397 from Morph1984/fs_util
common: fs: fs_util: Add more string conversion functions
Diffstat (limited to 'src/common/fs/fs_util.h')
-rw-r--r-- | src/common/fs/fs_util.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/fs/fs_util.h b/src/common/fs/fs_util.h index 951df53b6..ec9950ee7 100644 --- a/src/common/fs/fs_util.h +++ b/src/common/fs/fs_util.h @@ -5,9 +5,13 @@ #pragma once #include <concepts> +#include <filesystem> +#include <span> #include <string> #include <string_view> +#include "common/common_types.h" + namespace Common::FS { template <typename T> @@ -22,4 +26,33 @@ concept IsChar = std::same_as<T, char>; */ [[nodiscard]] std::u8string ToU8String(std::string_view utf8_string); +/** + * Converts a buffer of bytes to a UTF8-encoded std::u8string. + * 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::u8string. + */ +[[nodiscard]] std::u8string BufferToU8String(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 + * + * @returns UTF-8 encoded std::string. + */ +[[nodiscard]] std::string ToUTF8String(std::u8string_view u8_string); + +/** + * Converts a filesystem path to a UTF-8 encoded std::string. + * + * @param path Filesystem path + * + * @returns UTF-8 encoded std::string. + */ +[[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path); + } // namespace Common::FS |