MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / normalisePath

Function normalisePath

lib/FsHelpers/FsHelpers.cpp:39–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39std::string normalisePath(const std::string& path) {
40 std::vector<std::string_view> components;
41 components.reserve(8); // Eight nested folders is more than we might expect
42
43 size_t start = 0;
44 for (size_t i = 0; i <= path.length(); ++i) {
45 if (i == path.length() || path[i] == '/') {
46 if (i > start) {
47 std::string_view component(path.data() + start, i - start);
48 if (component == "..") {
49 if (!components.empty()) {
50 components.pop_back();
51 }
52 } else {
53 components.push_back(component);
54 }
55 }
56 start = i + 1;
57 }
58 }
59
60 if (components.empty()) {
61 return "";
62 }
63
64 size_t total_len = 0;
65 for (const auto& c : components) {
66 total_len += c.length() + 1;
67 }
68
69 std::string result;
70 result.reserve(total_len - 1);
71
72 for (size_t i = 0; i < components.size(); ++i) {
73 if (i > 0) {
74 result += '/';
75 }
76 result.append(components[i].data(), components[i].length());
77 }
78
79 return result;
80}
81
82void sortFileList(std::vector<std::string>& strs) {
83 std::sort(begin(strs), end(strs), [](const std::string& str1, const std::string& str2) {

Callers 13

parseContentOpfMethod · 0.85
getItemSizeMethod · 0.85
buildBookBinMethod · 0.85
startElementMethod · 0.85
startElementMethod · 0.85
endElementMethod · 0.85
endElementMethod · 0.85
getRequestPathMethod · 0.85
getDestinationPathMethod · 0.85

Calls 3

push_backMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected