| 60 | static const HashMap<char32_t, String> special_characters_map = _init_map(); |
| 61 | |
| 62 | String simplify_path(const String &path) { |
| 63 | String s = path; |
| 64 | String drive; |
| 65 | |
| 66 | // Check if we have a special path (like res://) or a protocol identifier. |
| 67 | int p = s.find("://"); |
| 68 | bool found = false; |
| 69 | if (p > 0) { |
| 70 | bool only_chars = true; |
| 71 | for (int i = 0; i < p; i++) { |
| 72 | if (!is_ascii_alphanumeric_char(s[i])) { |
| 73 | only_chars = false; |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | if (only_chars) { |
| 78 | found = true; |
| 79 | drive = s.substr(0, p + 3); |
| 80 | s = s.substr(p + 3); |
| 81 | } |
| 82 | } |
| 83 | if (!found) { |
| 84 | if (path.is_network_share_path()) { |
| 85 | // Network path, beginning with // or \\. |
| 86 | drive = s.substr(0, 2); |
| 87 | s = s.substr(2); |
| 88 | } else if (s.begins_with("/") || s.begins_with("\\")) { |
| 89 | // Absolute path. |
| 90 | drive = s.substr(0, 1); |
| 91 | s = s.substr(1); |
| 92 | } else { |
| 93 | // Windows-style drive path, like C:/ or C:\. |
| 94 | p = s.find(":/"); |
| 95 | if (p == -1) { |
| 96 | p = s.find(":\\"); |
| 97 | } |
| 98 | if (p != -1 && p < s.find_char('/')) { |
| 99 | drive = s.substr(0, p + 2); |
| 100 | s = s.substr(p + 2); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // s = s.replace("\\", "/"); |
| 106 | while (true) { // in case of using 2 or more slash |
| 107 | String compare = s.replace("//", "/"); |
| 108 | if (s == compare) { |
| 109 | break; |
| 110 | } else { |
| 111 | s = compare; |
| 112 | } |
| 113 | } |
| 114 | Vector<String> dirs = s.split("/", false); |
| 115 | |
| 116 | for (int i = 0; i < dirs.size(); i++) { |
| 117 | String d = dirs[i]; |
| 118 | if (d == ".") { |
| 119 | dirs.remove_at(i); |
no test coverage detected