Handle abnormal directives prefixes
This commit is contained in:
parent
ed3d5dffc0
commit
ec9a138e1a
@ -34,9 +34,10 @@ bool Directives::Shared::empty() const {
|
|||||||
return entries.empty();
|
return entries.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
Directives::Shared::Shared(List<Entry>&& givenEntries, String&& givenString) {
|
Directives::Shared::Shared(List<Entry>&& givenEntries, String&& givenString, StringView givenPrefix) {
|
||||||
entries = move(givenEntries);
|
entries = move(givenEntries);
|
||||||
string = move(givenString);
|
string = move(givenString);
|
||||||
|
prefix = givenPrefix;
|
||||||
hash = XXH3_64bits(string.utf8Ptr(), string.utf8Size());
|
hash = XXH3_64bits(string.utf8Ptr(), string.utf8Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,23 +59,27 @@ void Directives::parse(String&& directives) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
List<Entry> newList;
|
List<Entry> newList;
|
||||||
|
StringView view(directives);
|
||||||
StringView(directives).forEachSplitView("?", [&](StringView split, size_t beg, size_t end) {
|
StringView prefix = "";
|
||||||
|
view.forEachSplitView("?", [&](StringView split, size_t beg, size_t end) {
|
||||||
if (!split.empty()) {
|
if (!split.empty()) {
|
||||||
try {
|
try {
|
||||||
ImageOperation operation = imageOperationFromString(split);
|
ImageOperation operation = imageOperationFromString(split);
|
||||||
newList.emplace_back(move(operation), beg, end);
|
newList.emplace_back(move(operation), beg, end);
|
||||||
}
|
}
|
||||||
catch (StarException const& e) {
|
catch (StarException const& e) {
|
||||||
|
if (beg == 0)
|
||||||
|
prefix = split;
|
||||||
|
else
|
||||||
newList.emplace_back(ErrorImageOperation{ std::current_exception() }, beg, end);
|
newList.emplace_back(ErrorImageOperation{ std::current_exception() }, beg, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newList.empty())
|
if (newList.empty() && !prefix.empty())
|
||||||
return;
|
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 {
|
String Directives::string() const {
|
||||||
@ -84,6 +89,13 @@ String Directives::string() const {
|
|||||||
return shared->string;
|
return shared->string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringView Directives::prefix() const {
|
||||||
|
if (!shared)
|
||||||
|
return "";
|
||||||
|
else
|
||||||
|
return shared->prefix;
|
||||||
|
}
|
||||||
|
|
||||||
String const* Directives::stringPtr() const {
|
String const* Directives::stringPtr() const {
|
||||||
if (!shared)
|
if (!shared)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -93,17 +105,20 @@ String const* Directives::stringPtr() const {
|
|||||||
|
|
||||||
|
|
||||||
String Directives::buildString() const {
|
String Directives::buildString() const {
|
||||||
String built;
|
|
||||||
if (shared) {
|
if (shared) {
|
||||||
|
String built = shared->prefix;
|
||||||
|
|
||||||
for (auto& entry : shared->entries) {
|
for (auto& entry : shared->entries) {
|
||||||
built += "?";
|
built += "?";
|
||||||
built += entry.string(*shared);
|
built += entry.string(*shared);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return built;
|
return built;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
String& Directives::addToString(String& out) const {
|
String& Directives::addToString(String& out) const {
|
||||||
if (!empty())
|
if (!empty())
|
||||||
out += shared->string;
|
out += shared->string;
|
||||||
|
@ -30,10 +30,11 @@ public:
|
|||||||
struct Shared {
|
struct Shared {
|
||||||
List<Entry> entries;
|
List<Entry> entries;
|
||||||
String string;
|
String string;
|
||||||
|
StringView prefix;
|
||||||
size_t hash = 0;
|
size_t hash = 0;
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
Shared(List<Entry>&& givenEntries, String&& givenString);
|
Shared(List<Entry>&& givenEntries, String&& givenString, StringView givenPrefix);
|
||||||
};
|
};
|
||||||
|
|
||||||
Directives();
|
Directives();
|
||||||
@ -43,6 +44,7 @@ public:
|
|||||||
|
|
||||||
void parse(String&& directives);
|
void parse(String&& directives);
|
||||||
String string() const;
|
String string() const;
|
||||||
|
StringView prefix() const;
|
||||||
String const* stringPtr() const;
|
String const* stringPtr() const;
|
||||||
String buildString() const;
|
String buildString() const;
|
||||||
String& addToString(String& out) const;
|
String& addToString(String& out) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user