summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fs/fs_util.cpp14
-rw-r--r--src/common/fs/fs_util.h33
-rw-r--r--src/common/fs/path_util.cpp6
-rw-r--r--src/common/fs/path_util.h9
4 files changed, 47 insertions, 15 deletions
diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp
index 0ddfc3131..357cf5855 100644
--- a/src/common/fs/fs_util.cpp
+++ b/src/common/fs/fs_util.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
6
5#include "common/fs/fs_util.h" 7#include "common/fs/fs_util.h"
6 8
7namespace Common::FS { 9namespace Common::FS {
@@ -10,4 +12,16 @@ std::u8string ToU8String(std::string_view utf8_string) {
10 return std::u8string{utf8_string.begin(), utf8_string.end()}; 12 return std::u8string{utf8_string.begin(), utf8_string.end()};
11} 13}
12 14
15std::u8string BufferToU8String(std::span<const u8> buffer) {
16 return std::u8string{buffer.begin(), std::ranges::find(buffer, u8{0})};
17}
18
19std::string ToUTF8String(std::u8string_view u8_string) {
20 return std::string{u8_string.begin(), u8_string.end()};
21}
22
23std::string PathToUTF8String(const std::filesystem::path& path) {
24 return ToUTF8String(path.u8string());
25}
26
13} // namespace Common::FS 27} // namespace Common::FS
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
11namespace Common::FS { 15namespace Common::FS {
12 16
13template <typename T> 17template <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
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index 8b732a21c..6cdd14f13 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -129,12 +129,6 @@ private:
129 std::unordered_map<YuzuPath, fs::path> yuzu_paths; 129 std::unordered_map<YuzuPath, fs::path> yuzu_paths;
130}; 130};
131 131
132std::string PathToUTF8String(const fs::path& path) {
133 const auto utf8_string = path.u8string();
134
135 return std::string{utf8_string.begin(), utf8_string.end()};
136}
137
138bool ValidatePath(const fs::path& path) { 132bool ValidatePath(const fs::path& path) {
139 if (path.empty()) { 133 if (path.empty()) {
140 LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path)); 134 LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path));
diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h
index a9fadbceb..14e8c35d7 100644
--- a/src/common/fs/path_util.h
+++ b/src/common/fs/path_util.h
@@ -26,15 +26,6 @@ enum class YuzuPath {
26}; 26};
27 27
28/** 28/**
29 * Converts a filesystem path to a UTF-8 encoded std::string.
30 *
31 * @param path Filesystem path
32 *
33 * @returns UTF-8 encoded std::string.
34 */
35[[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path);
36
37/**
38 * Validates a given path. 29 * Validates a given path.
39 * 30 *
40 * A given path is valid if it meets these conditions: 31 * A given path is valid if it meets these conditions: