ReXGlue SDK
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <initializer_list>
16#include <string>
17#include <string_view>
18#include <vector>
19
20#include <rex/platform.h>
21#include <rex/types.h>
22
23namespace rex::string {
24
25constexpr char32_t kUTF8PathSeparator = static_cast<char32_t>(rex::platform::kPathSeparator);
26constexpr char32_t kUTF8GuestPathSeparator = U'\\';
27
33REX_API std::vector<std::string_view> utf8_split_path(const std::string_view path);
34
35REX_API std::string_view utf8_strip_leading_slashes(const std::string_view path);
36
43REX_API std::string utf8_join_paths(const std::string_view left_path,
44 const std::string_view right_path,
45 char32_t separator = kUTF8PathSeparator);
46
47REX_API std::string utf8_join_paths(const std::vector<std::string>& paths,
48 char32_t separator = kUTF8PathSeparator);
49
50REX_API std::string utf8_join_paths(const std::vector<std::string_view>& paths,
51 char32_t separator = kUTF8PathSeparator);
52
53inline std::string utf8_join_paths(std::initializer_list<const std::string_view> paths,
54 char32_t separator = kUTF8PathSeparator) {
55 std::string result;
56 for (auto path : paths) {
57 result = utf8_join_paths(result, path, separator);
58 }
59 return result;
60}
61
62inline std::string utf8_join_guest_paths(const std::string_view left_path,
63 const std::string_view right_path) {
64 return utf8_join_paths(left_path, right_path, kUTF8GuestPathSeparator);
65}
66
67inline std::string utf8_join_guest_paths(const std::vector<std::string>& paths) {
68 return utf8_join_paths(paths, kUTF8GuestPathSeparator);
69}
70
71inline std::string utf8_join_guest_paths(const std::vector<std::string_view>& paths) {
72 return utf8_join_paths(paths, kUTF8GuestPathSeparator);
73}
74
75inline std::string utf8_join_guest_paths(std::initializer_list<const std::string_view> paths) {
76 return utf8_join_paths(paths, kUTF8GuestPathSeparator);
77}
78
80REX_API std::string utf8_fix_path_separators(const std::string_view path,
81 char32_t new_separator = kUTF8PathSeparator);
82
87REX_API std::string utf8_find_name_from_path(const std::string_view path,
88 char32_t separator = kUTF8PathSeparator);
89
90inline std::string utf8_find_name_from_guest_path(const std::string_view path) {
91 return utf8_find_name_from_path(path, kUTF8GuestPathSeparator);
92}
93
98REX_API std::string utf8_find_base_name_from_path(const std::string_view path,
99 char32_t separator = kUTF8PathSeparator);
100
101inline std::string utf8_find_base_name_from_guest_path(const std::string_view path) {
102 return utf8_find_base_name_from_path(path, kUTF8GuestPathSeparator);
103}
104
109REX_API std::string utf8_find_base_path(const std::string_view path,
110 char32_t separator = kUTF8PathSeparator);
111
112inline std::string utf8_find_base_guest_path(const std::string_view path) {
113 return utf8_find_base_path(path, kUTF8GuestPathSeparator);
114}
115
121REX_API std::string utf8_canonicalize_path(const std::string_view path,
122 char32_t separator = kUTF8PathSeparator);
123
125REX_API std::string NormalizeGuestPath(std::string_view path);
126
127inline std::string utf8_canonicalize_guest_path(const std::string_view path) {
128 return utf8_canonicalize_path(path, kUTF8GuestPathSeparator);
129}
130
131} // namespace rex::string
std::string utf8_canonicalize_path(const std::string_view path, char32_t separator=kUTF8PathSeparator)
std::vector< std::string_view > utf8_split_path(const std::string_view path)
std::string utf8_join_paths(const std::string_view left_path, const std::string_view right_path, char32_t separator=kUTF8PathSeparator)
std::string utf8_find_base_name_from_path(const std::string_view path, char32_t separator=kUTF8PathSeparator)
std::string utf8_find_name_from_path(const std::string_view path, char32_t separator=kUTF8PathSeparator)
std::string utf8_fix_path_separators(const std::string_view path, char32_t new_separator=kUTF8PathSeparator)
std::string NormalizeGuestPath(std::string_view path)
std::string utf8_find_base_path(const std::string_view path, char32_t separator=kUTF8PathSeparator)
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Integer types, byte order wrappers and size literals.