diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-26 15:34:41 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-26 15:34:41 +1000 |
commit | ec9a138e1acb648b7eb1da44e081553a1586185b (patch) | |
tree | ac1833f4ea34358b5a06f0bd27f94f51a355ac13 /source/core/StarDirectives.cpp | |
parent | ed3d5dffc099b1c5bcb14451fffc63de1b6ac634 (diff) |
Handle abnormal directives prefixes
Diffstat (limited to 'source/core/StarDirectives.cpp')
-rw-r--r-- | source/core/StarDirectives.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp index 7149f70..cac1eaf 100644 --- a/source/core/StarDirectives.cpp +++ b/source/core/StarDirectives.cpp @@ -34,9 +34,10 @@ bool Directives::Shared::empty() const { return entries.empty(); } -Directives::Shared::Shared(List<Entry>&& givenEntries, String&& givenString) { +Directives::Shared::Shared(List<Entry>&& givenEntries, String&& givenString, StringView givenPrefix) { entries = move(givenEntries); string = move(givenString); + prefix = givenPrefix; hash = XXH3_64bits(string.utf8Ptr(), string.utf8Size()); } @@ -58,23 +59,27 @@ void Directives::parse(String&& directives) { return; List<Entry> newList; - - StringView(directives).forEachSplitView("?", [&](StringView split, size_t beg, size_t end) { + StringView view(directives); + StringView prefix = ""; + view.forEachSplitView("?", [&](StringView split, size_t beg, size_t end) { if (!split.empty()) { try { ImageOperation operation = imageOperationFromString(split); newList.emplace_back(move(operation), beg, end); } catch (StarException const& e) { - newList.emplace_back(ErrorImageOperation{ std::current_exception() }, beg, end); + if (beg == 0) + prefix = split; + else + newList.emplace_back(ErrorImageOperation{ std::current_exception() }, beg, end); } } }); - if (newList.empty()) + if (newList.empty() && !prefix.empty()) return; - shared = std::make_shared<Shared const>(move(newList), move(directives)); + shared = std::make_shared<Shared const>(move(newList), move(directives), prefix); } String Directives::string() const { @@ -84,6 +89,13 @@ String Directives::string() const { return shared->string; } +StringView Directives::prefix() const { + if (!shared) + return ""; + else + return shared->prefix; +} + String const* Directives::stringPtr() const { if (!shared) return nullptr; @@ -93,15 +105,18 @@ String const* Directives::stringPtr() const { String Directives::buildString() const { - String built; if (shared) { + String built = shared->prefix; + for (auto& entry : shared->entries) { built += "?"; built += entry.string(*shared); } + + return built; } - return built; + return String(); } String& Directives::addToString(String& out) const { |