You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Make String.simplify_path keep the protocol identifier for urls
This commit is contained in:
@@ -3667,32 +3667,43 @@ bool String::is_network_share_path() const {
|
||||
String String::simplify_path() const {
|
||||
String s = *this;
|
||||
String drive;
|
||||
if (s.begins_with("local://")) {
|
||||
drive = "local://";
|
||||
s = s.substr(8);
|
||||
} else if (s.begins_with("res://")) {
|
||||
drive = "res://";
|
||||
s = s.substr(6);
|
||||
} else if (s.begins_with("user://")) {
|
||||
drive = "user://";
|
||||
s = s.substr(7);
|
||||
} else if (s.begins_with("uid://")) {
|
||||
drive = "uid://";
|
||||
s = s.substr(6);
|
||||
} else if (is_network_share_path()) {
|
||||
drive = s.substr(0, 2);
|
||||
s = s.substr(2, s.length() - 2);
|
||||
} else if (s.begins_with("/") || s.begins_with("\\")) {
|
||||
drive = s.substr(0, 1);
|
||||
s = s.substr(1, s.length() - 1);
|
||||
} else {
|
||||
int p = s.find(":/");
|
||||
if (p == -1) {
|
||||
p = s.find(":\\");
|
||||
|
||||
// Check if we have a special path (like res://) or a protocol identifier.
|
||||
int p = s.find("://");
|
||||
bool found = false;
|
||||
if (p > 0) {
|
||||
bool only_chars = true;
|
||||
for (int i = 0; i < p; i++) {
|
||||
if (!is_ascii_char(s[i])) {
|
||||
only_chars = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p != -1 && p < s.find("/")) {
|
||||
drive = s.substr(0, p + 2);
|
||||
s = s.substr(p + 2);
|
||||
if (only_chars) {
|
||||
found = true;
|
||||
drive = s.substr(0, p + 3);
|
||||
s = s.substr(p + 3);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (is_network_share_path()) {
|
||||
// Network path, beginning with // or \\.
|
||||
drive = s.substr(0, 2);
|
||||
s = s.substr(2);
|
||||
} else if (s.begins_with("/") || s.begins_with("\\")) {
|
||||
// Absolute path.
|
||||
drive = s.substr(0, 1);
|
||||
s = s.substr(1);
|
||||
} else {
|
||||
// Windows-style drive path, like C:/ or C:\.
|
||||
p = s.find(":/");
|
||||
if (p == -1) {
|
||||
p = s.find(":\\");
|
||||
}
|
||||
if (p != -1 && p < s.find("/")) {
|
||||
drive = s.substr(0, p + 2);
|
||||
s = s.substr(p + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user