MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / getCaseSensitivePath

Method getCaseSensitivePath

src/utils/Utils.cpp:117–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117std::string Utils::getCaseSensitivePath(const std::string& caseInsensitivePath, const std::string& prePath)
118{
119 // Transform input path to lower
120 std::string pathLower = caseInsensitivePath;
121 std::transform(pathLower.begin(), pathLower.end(), pathLower.begin(), ::tolower);
122
123 // Split the input-path at /
124 std::vector<std::string> parts = Utils::split(pathLower, "/\\");
125
126 // Get a complete directory listing
127 auto getListing = [&](const std::string& directory) {
128
129 std::vector<std::string> content;
130
131 tinydir_dir dir;
132 if (tinydir_open(&dir, directory.c_str()) == -1)
133 {
134 tinydir_close(&dir);
135 return content;
136 }
137
138 while (dir.has_next)
139 {
140 tinydir_file file;
141 if (tinydir_readfile(&dir, &file) == -1)
142 {
143 tinydir_close(&dir);
144 return content;
145 }
146
147 content.push_back(file.name);
148
149 tinydir_next(&dir);
150 }
151
152 tinydir_close(&dir);
153 return content;
154 };
155
156 // Get the case sensitive version for every part of the path
157 std::string result = caseInsensitivePath.front() == '/' ? "/." : "./.";
158
159 if (!prePath.empty())
160 result = prePath;
161
162 for (size_t i = 0; i < parts.size(); i++)
163 {
164 std::vector<std::string> listing = getListing(result);
165
166 bool found = false;
167 for (size_t j = 0; j < listing.size(); j++)
168 {
169 // Transform to lowercase
170 std::string lw = listing[j];
171 std::transform(lw.begin(), lw.end(), lw.begin(), ::tolower);
172
173 // Append the path in original casing
174 if (parts[i] == lw)

Callers

nothing calls this directly

Calls 6

push_backMethod · 0.80
frontMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected