summaryrefslogtreecommitdiff
path: root/core/string
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-09-13 16:49:24 +0200
committerGitHub <noreply@github.com>2021-09-13 16:49:24 +0200
commit41562b91982074a4ab9c1f151cca1ec0681fc356 (patch)
treed326e96121c282349ccf6e3b86b15985afee61e5 /core/string
parentf85426e8ad22e2ce875d3b686ab2dfdfa1ecc877 (diff)
parentcc78405b12728ede89f53e2a9f6f65a3eb6ee730 (diff)
Merge pull request #52049 from theraot/master
Diffstat (limited to 'core/string')
-rw-r--r--core/string/ustring.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index ed6fd13cc8..8416ff929e 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4329,23 +4329,39 @@ bool String::is_relative_path() const {
}
String String::get_base_dir() const {
- int basepos = find(":/");
- if (basepos == -1) {
- basepos = find(":\\");
+ int end = 0;
+
+ // url scheme style base
+ int basepos = find("://");
+ if (basepos != -1) {
+ end = basepos + 3;
}
+
+ // windows top level directory base
+ if (end == 0) {
+ basepos = find(":/");
+ if (basepos == -1) {
+ basepos = find(":\\");
+ }
+ if (basepos != -1) {
+ end = basepos + 2;
+ }
+ }
+
+ // unix root directory base
+ if (end == 0) {
+ if (begins_with("/")) {
+ end = 1;
+ }
+ }
+
String rs;
String base;
- if (basepos != -1) {
- int end = basepos + 3;
+ if (end != 0) {
rs = substr(end, length());
base = substr(0, end);
} else {
- if (begins_with("/")) {
- rs = substr(1, length());
- base = "/";
- } else {
- rs = *this;
- }
+ rs = *this;
}
int sep = MAX(rs.rfind("/"), rs.rfind("\\"));