Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarAssetPath.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 01:04:58 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 01:04:58 +1000
commit4e6e342169e2dc8f86960bc31840e3a3b281814a (patch)
tree6b327e196879fbdb85ef512e593fb42b7ed1f57f /source/core/StarAssetPath.cpp
parent63b68b3a55a11b32b07e7b8bdbf3760722d5e7f9 (diff)
Improve AssetPath::split
also fixed a bug with the cursor changes
Diffstat (limited to 'source/core/StarAssetPath.cpp')
-rw-r--r--source/core/StarAssetPath.cpp54
1 files changed, 18 insertions, 36 deletions
diff --git a/source/core/StarAssetPath.cpp b/source/core/StarAssetPath.cpp
index 90116bb..a99ecfa 100644
--- a/source/core/StarAssetPath.cpp
+++ b/source/core/StarAssetPath.cpp
@@ -25,52 +25,34 @@ static Maybe<pair<size_t, size_t>> findFilenameRange(std::string const& pathUtf8
}
AssetPath AssetPath::split(String const& path) {
- auto i = path.begin();
- auto end = path.end();
-
AssetPath components;
- // base paths cannot have any ':' or '?' characters, stop at the first one.
- while (i != end) {
- String::Char c = *i;
- if (c == ':' || c == '?')
- break;
+ std::string const& str = path.utf8();
- components.basePath += c;
- ++i;
- }
+ //base paths cannot have any ':' or '?' characters, stop at the first one.
+ size_t end = str.find_first_of(":?");
+ components.basePath = str.substr(0, end);
+
+ if (end == NPos)
+ return components;
// Sub-paths must immediately follow base paths and must start with a ':',
// after this point any further ':' characters are not special.
- if (i != end && *i == ':') {
- ++i;
- while (i != end) {
- String::Char c = *i;
- if (c == '?')
- break;
-
- if (!components.subPath)
- components.subPath.emplace();
-
- *components.subPath += c;
- ++i;
- }
+ if (str[end] == ':') {
+ size_t beg = end;
+ end = str.find_first_of("?", beg);
+ size_t len = end - beg - 1;
+ if (len)
+ components.subPath.emplace(str.substr(beg + 1, len));
}
+ if (end == NPos)
+ return components;
+
// Directives must follow the base path and optional sub-path, and each
// directive is separated by one or more '?' characters.
- while (i != end && *i == '?') {
- String directives;
- while (i != end) {
- directives.append(*i);
- ++i;
- }
-
- if (!directives.empty())
- components.directives.append(move(directives));
- }
-
- starAssert(i == end);
+ if (str[end] == '?')
+ components.directives = String(str.substr(end));
return components;
}