| 173 | // `get_base_dir()` but with escaped glob characters |
| 174 | |
| 175 | String get_base_dir(const String &path) { |
| 176 | int end = 0; |
| 177 | |
| 178 | // URL scheme style base. |
| 179 | int basepos = path.find("://"); |
| 180 | if (basepos != -1) { |
| 181 | end = basepos + 3; |
| 182 | } |
| 183 | |
| 184 | // Windows top level directory base. |
| 185 | if (end == 0) { |
| 186 | basepos = path.find(":/"); |
| 187 | if (basepos == -1) { |
| 188 | basepos = path.find(":\\"); |
| 189 | } |
| 190 | if (basepos != -1) { |
| 191 | end = basepos + 2; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // Windows UNC network share path. |
| 196 | if (end == 0) { |
| 197 | if (path.is_network_share_path()) { |
| 198 | basepos = path.find_char('/', 2); |
| 199 | if (basepos == -1) { |
| 200 | basepos = path.find_char('\\', 2); |
| 201 | } |
| 202 | int servpos = path.find_char('/', basepos + 1); |
| 203 | if (servpos == -1) { |
| 204 | servpos = path.find_char('\\', basepos + 1); |
| 205 | } |
| 206 | if (servpos != -1) { |
| 207 | end = servpos + 1; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Unix root directory base. |
| 213 | if (end == 0) { |
| 214 | if (path.begins_with("/")) { |
| 215 | end = 1; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | String rs; |
| 220 | String base; |
| 221 | if (end != 0) { |
| 222 | rs = path.substr(end, path.length()); |
| 223 | base = path.substr(0, end); |
| 224 | } else { |
| 225 | rs = path; |
| 226 | } |
| 227 | |
| 228 | int sep = get_last_dir_sep(rs); |
| 229 | if (sep == -1) { |
| 230 | return base; |
| 231 | } |
| 232 |
no test coverage detected