MyGUI 3.5.3
MyGUI_FileSystemUtility.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_FILE_SYSTEM_UTILITY_H_
8#define MYGUI_FILE_SYSTEM_UTILITY_H_
9
10#include "MyGUI_UString.h"
11#include <filesystem>
12#include <string>
13#include <string_view>
14
16{
17
19 inline std::filesystem::path toPath(std::string_view text)
20 {
21 if (text.empty())
22 return {};
23
24 return std::filesystem::u8path(text.data(), text.data() + text.size());
25 }
26
28 inline std::filesystem::path toPath(const char* text)
29 {
30 return toPath(std::string_view(text));
31 }
32
34 inline std::filesystem::path toPath(const std::string& text)
35 {
36 return toPath(std::string_view(text));
37 }
38
40 inline std::filesystem::path toPath(const UString& text)
41 {
42 return toPath(text.asUTF8());
43 }
44
46 inline std::string toUtf8(const std::filesystem::path& path)
47 {
48 const auto text = path.u8string();
49 return {text.begin(), text.end()};
50 }
51
52} // namespace MyGUI::utility
53
54#endif // MYGUI_FILE_SYSTEM_UTILITY_H_
std::string toUtf8(const std::filesystem::path &path)
Convert a filesystem path to UTF-8 bytes.
std::filesystem::path toPath(std::string_view text)
Convert UTF-8 bytes to a native filesystem path.