| 5256 | } |
| 5257 | |
| 5258 | String String::get_base_dir() const { |
| 5259 | int end = 0; |
| 5260 | |
| 5261 | // URL scheme style base. |
| 5262 | int basepos = find("://"); |
| 5263 | if (basepos != -1) { |
| 5264 | end = basepos + 3; |
| 5265 | } |
| 5266 | |
| 5267 | // Windows top level directory base. |
| 5268 | if (end == 0) { |
| 5269 | basepos = find(":/"); |
| 5270 | if (basepos == -1) { |
| 5271 | basepos = find(":\\"); |
| 5272 | } |
| 5273 | if (basepos != -1) { |
| 5274 | end = basepos + 2; |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | // Windows UNC network share path. |
| 5279 | if (end == 0) { |
| 5280 | if (is_network_share_path()) { |
| 5281 | basepos = find_char('/', 2); |
| 5282 | if (basepos == -1) { |
| 5283 | basepos = find_char('\\', 2); |
| 5284 | } |
| 5285 | int servpos = find_char('/', basepos + 1); |
| 5286 | if (servpos == -1) { |
| 5287 | servpos = find_char('\\', basepos + 1); |
| 5288 | } |
| 5289 | if (servpos != -1) { |
| 5290 | end = servpos + 1; |
| 5291 | } |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | // Unix root directory base. |
| 5296 | if (end == 0) { |
| 5297 | if (begins_with("/")) { |
| 5298 | end = 1; |
| 5299 | } |
| 5300 | } |
| 5301 | |
| 5302 | String rs; |
| 5303 | String base; |
| 5304 | if (end != 0) { |
| 5305 | rs = substr(end, length()); |
| 5306 | base = substr(0, end); |
| 5307 | } else { |
| 5308 | rs = *this; |
| 5309 | } |
| 5310 | |
| 5311 | int sep = MAX(rs.rfind_char('/'), rs.rfind_char('\\')); |
| 5312 | if (sep == -1) { |
| 5313 | return base; |
| 5314 | } |
| 5315 | |