MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / simplify_path

Method simplify_path

core/string/ustring.cpp:4413–4491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4411}
4412
4413String String::simplify_path() const {
4414 String s = *this;
4415 String drive;
4416
4417 // Check if we have a special path (like res://) or a protocol identifier.
4418 int p = s.find("://");
4419 bool found = false;
4420 if (p > 0) {
4421 bool only_chars = true;
4422 for (int i = 0; i < p; i++) {
4423 if (!is_ascii_alphanumeric_char(s[i])) {
4424 only_chars = false;
4425 break;
4426 }
4427 }
4428 if (only_chars) {
4429 found = true;
4430 drive = s.substr(0, p + 3);
4431 s = s.substr(p + 3);
4432 }
4433 }
4434 if (!found) {
4435 if (is_network_share_path()) {
4436 // Network path, beginning with // or \\.
4437 drive = s.substr(0, 2);
4438 s = s.substr(2);
4439 } else if (s.begins_with("/") || s.begins_with("\\")) {
4440 // Absolute path.
4441 drive = s.substr(0, 1);
4442 s = s.substr(1);
4443 } else {
4444 // Windows-style drive path, like C:/ or C:\.
4445 p = s.find(":/");
4446 if (p == -1) {
4447 p = s.find(":\\");
4448 }
4449 if (p != -1 && p < s.find_char('/')) {
4450 drive = s.substr(0, p + 2);
4451 s = s.substr(p + 2);
4452 }
4453 }
4454 }
4455
4456 s = s.replace_char('\\', '/');
4457 while (true) { // in case of using 2 or more slash
4458 String compare = s.replace("//", "/");
4459 if (s == compare) {
4460 break;
4461 } else {
4462 s = compare;
4463 }
4464 }
4465 Vector<String> dirs = s.split("/", false);
4466
4467 for (int i = 0; i < dirs.size(); i++) {
4468 String d = dirs[i];
4469 if (d == ".") {
4470 dirs.remove_at(i);

Callers 15

make_dir_recursiveMethod · 0.45
rename_dependenciesMethod · 0.45
add_file_removalMethod · 0.45
add_fileMethod · 0.45
_validate_local_pathMethod · 0.45
RotatedFileLoggerMethod · 0.45
add_pathMethod · 0.45
remove_pathMethod · 0.45
get_file_hashMethod · 0.45
FileAccessPackMethod · 0.45
_find_dirMethod · 0.45
get_sizeMethod · 0.45

Calls 10

substrMethod · 0.80
begins_withMethod · 0.80
find_charMethod · 0.80
replace_charMethod · 0.80
splitMethod · 0.80
sizeMethod · 0.65
findMethod · 0.45
replaceMethod · 0.45
remove_atMethod · 0.45

Tested by

no test coverage detected