| 156 | } |
| 157 | |
| 158 | std::string SanitizePath(const std::string_view &view) { |
| 159 | std::string path; |
| 160 | path.reserve(view.length()); |
| 161 | |
| 162 | // Was the last character a delimiter? |
| 163 | bool wasDelim = false; |
| 164 | |
| 165 | // Construct new string |
| 166 | for (size_t i = 0; i < view.length(); i++) { |
| 167 | bool isDelim = IsPathDelim(view[i]); |
| 168 | |
| 169 | // Skip if the last was a delimiter |
| 170 | if (wasDelim && isDelim) { |
| 171 | continue; |
| 172 | } |
| 173 | |
| 174 | // Set state |
| 175 | wasDelim = isDelim; |
| 176 | |
| 177 | // Sanitize delims |
| 178 | char _char; |
| 179 | switch (view[i]) { |
| 180 | default: |
| 181 | _char = view[i]; |
| 182 | break; |
| 183 | case '/': |
| 184 | _char = '\\'; |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | // Add character |
| 189 | path.insert(path.end(), _char); |
| 190 | } |
| 191 | |
| 192 | // OK |
| 193 | return path; |
| 194 | } |
| 195 | |
| 196 | bool PathExists(const std::string& view) { |
| 197 | struct stat buffer; |
no test coverage detected