diff options
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 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <concepts> | 7 | #include <concepts> |
| 8 | #include <filesystem> | ||
| 9 | #include <span> | ||
| 8 | #include <string> | 10 | #include <string> |
| 9 | #include <string_view> | 11 | #include <string_view> |
| 10 | 12 | ||
| 13 | #include "common/common_types.h" | ||
| 14 | |||
| 11 | namespace Common::FS { | 15 | namespace Common::FS { |
| 12 | 16 | ||
| 13 | template <typename T> | 17 | template <typename T> |
| @@ -22,4 +26,33 @@ concept IsChar = std::same_as<T, char>; | |||
| 22 | */ | 26 | */ |
| 23 | [[nodiscard]] std::u8string ToU8String(std::string_view utf8_string); | 27 | [[nodiscard]] std::u8string ToU8String(std::string_view utf8_string); |
| 24 | 28 | ||
| 29 | /** | ||
| 30 | * Converts a buffer of bytes to a UTF8-encoded std::u8string. | ||
| 31 | * This converts from the start of the buffer until the first encountered null-terminator. | ||
| 32 | * If no null-terminator is found, this converts the entire buffer instead. | ||
| 33 | * | ||
| 34 | * @param buffer Buffer of bytes | ||
| 35 | * | ||
| 36 | * @returns UTF-8 encoded std::u8string. | ||
| 37 | */ | ||
| 38 | [[nodiscard]] std::u8string BufferToU8String(std::span<const u8> buffer); | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Converts a std::u8string or std::u8string_view to a UTF-8 encoded std::string. | ||
| 42 | * | ||
| 43 | * @param u8_string UTF-8 encoded u8string | ||
| 44 | * | ||
| 45 | * @returns UTF-8 encoded std::string. | ||
| 46 | */ | ||
| 47 | [[nodiscard]] std::string ToUTF8String(std::u8string_view u8_string); | ||
| 48 | |||
| 49 | /** | ||
| 50 | * Converts a filesystem path to a UTF-8 encoded std::string. | ||
| 51 | * | ||
| 52 | * @param path Filesystem path | ||
| 53 | * | ||
| 54 | * @returns UTF-8 encoded std::string. | ||
| 55 | */ | ||
| 56 | [[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path); | ||
| 57 | |||
| 25 | } // namespace Common::FS | 58 | } // namespace Common::FS |