| 4411 | } |
| 4412 | |
| 4413 | String 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); |
no test coverage detected