diff options
-rw-r--r-- | source/core/StarDirectives.cpp | 31 | ||||
-rw-r--r-- | source/core/StarDirectives.hpp | 4 |
2 files changed, 26 insertions, 9 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 { diff --git a/source/core/StarDirectives.hpp b/source/core/StarDirectives.hpp index 1455dd0..8af2f51 100644 --- a/source/core/StarDirectives.hpp +++ b/source/core/StarDirectives.hpp @@ -30,10 +30,11 @@ public: struct Shared { List<Entry> entries; String string; + StringView prefix; size_t hash = 0; bool empty() const; - Shared(List<Entry>&& givenEntries, String&& givenString); + Shared(List<Entry>&& givenEntries, String&& givenString, StringView givenPrefix); }; Directives(); @@ -43,6 +44,7 @@ public: void parse(String&& directives); String string() const; + StringView prefix() const; String const* stringPtr() const; String buildString() const; String& addToString(String& out) const; |