diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-25 01:16:40 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-25 01:16:40 +1000 |
commit | 008bd6d3df469f69eaf667bc3ae357a03894bddb (patch) | |
tree | 0aa0548dae863c727cd32fc2b0d562783c7edb4e /source/core/StarDirectives.cpp | |
parent | 2bd399fd00d87683e37b41bfc1a25772c6cde71f (diff) |
more!! more!!!!
Diffstat (limited to 'source/core/StarDirectives.cpp')
-rw-r--r-- | source/core/StarDirectives.cpp | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp index 4a2ca4c..9214abf 100644 --- a/source/core/StarDirectives.cpp +++ b/source/core/StarDirectives.cpp @@ -23,23 +23,24 @@ Directives::Entry::Entry(Entry const& other) { Directives::Directives() : hash(0) {} Directives::Directives(String const& directives) : hash(0) { - parse(directives); + string = directives; + parse(string); } Directives::Directives(String&& directives) : hash(0) { - String mine = move(directives); - parse(mine); + string = move(directives); + parse(string); } -Directives::Directives(const char* directives) : hash(0) { - String string(directives); +Directives::Directives(const char* directives) : hash(0), string(directives) { parse(string); } Directives::Directives(List<Entry>&& newEntries) { entries = std::make_shared<List<Entry> const>(move(newEntries)); - String directives = toString(); // This needs to be better - hash = XXH3_64bits(directives.utf8Ptr(), directives.utf8Size()); + String newString; + string = move(buildString(newString)); + hash = XXH3_64bits(string.utf8Ptr(), string.utf8Size()); } void Directives::parse(String const& directives) { @@ -51,8 +52,12 @@ void Directives::parse(String const& directives) { newList.reserve(split.size()); for (String& str : split) { if (!str.empty()) { - ImageOperation operation = imageOperationFromString(str); - newList.emplace_back(move(operation), move(str)); + try { + ImageOperation operation = imageOperationFromString(str); + newList.emplace_back(move(operation), move(str)); + } catch (StarException const& e) { + Logger::logf(LogLevel::Error, "Error parsing image operation: %s", e.what()); + } } } @@ -65,27 +70,29 @@ void Directives::parse(String const& directives) { // Logger::logf(LogLevel::Debug, "Directives: Parsed %u character long string", directives.utf8Size()); } -void Directives::buildString(String& out) const { +String& Directives::buildString(String& out) const { if (entries) { for (auto& entry : *entries) { out += "?"; out += entry.string; } } + + return out; } String Directives::toString() const { - String result; - buildString(result); - //if (result.utf8Size() > 1000) - // Logger::logf(LogLevel::Debug, "Directives: Rebuilt %u character long string", result.utf8Size()); - return result; + return string; } inline bool Directives::empty() const { return !entries || entries->empty(); } +inline Directives::operator bool() const { + return !empty(); +} + DataStream& operator>>(DataStream& ds, Directives& directives) { String string; @@ -103,19 +110,37 @@ DataStream& operator<<(DataStream& ds, Directives const& directives) { } DirectivesGroup::DirectivesGroup() : m_count(0) {} -DirectivesGroup::DirectivesGroup(String const& directives) { - m_directives.emplace_back(directives); - m_count = m_directives.back().entries->size(); +DirectivesGroup::DirectivesGroup(String const& directives) : m_count(0) { + if (directives.empty()) + return; + + Directives parsed(directives); + if (parsed) { + m_directives.emplace_back(move(parsed)); + m_count = m_directives.back().entries->size(); + } } -DirectivesGroup::DirectivesGroup(String&& directives) { - m_directives.emplace_back(move(directives)); - m_count = m_directives.back().entries->size(); +DirectivesGroup::DirectivesGroup(String&& directives) : m_count(0) { + if (directives.empty()) { + directives.clear(); + return; + } + + Directives parsed(move(directives)); + if (parsed) { + m_directives.emplace_back(move(parsed)); + m_count = m_directives.back().entries->size(); + } } inline bool DirectivesGroup::empty() const { return m_count == 0; } +inline DirectivesGroup::operator bool() const { + return empty(); +} + inline bool DirectivesGroup::compare(DirectivesGroup const& other) const { if (m_count != other.m_count) return false; @@ -156,7 +181,7 @@ inline String DirectivesGroup::toString() const { void DirectivesGroup::addToString(String& string) const { for (auto& directives : m_directives) - directives.buildString(string); + string += directives.string; } void DirectivesGroup::forEach(DirectivesCallback callback) const { |