wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
path.cpp
Go to the documentation of this file.
2
3namespace wowlib {
4 std::string normalizePath(std::string_view path) {
5 std::string result;
6 result.reserve(path.size());
7
8 for (char c : path) {
9 if (c == '/') c = '\\';
10 else if (c >= 'A' && c <= 'Z') c = static_cast<char>(c - 'A' + 'a');
11
12 // collapse duplicate separators, drop a leading one
13 if (c == '\\' && (result.empty() || result.back() == '\\')) continue;
14
15 result.push_back(c);
16 }
17
18 if (!result.empty() && result.back() == '\\') result.pop_back();
19
20 return result;
21 }
22
23 std::string toNativeRelative(std::string_view canonical) {
24 std::string result{canonical};
25 for (char& c : result)
26 if (c == '\\') c = '/';
27 return result;
28 }
29}
std::string normalizePath(std::string_view path)
Canonicalize a client-internal file path.
Definition path.cpp:4
std::string toNativeRelative(std::string_view canonical)
Convert a canonical path to a forward-slash relative path for use on the native filesystem (project-d...
Definition path.cpp:23
Client-internal path canonicalization.