| 124 | } |
| 125 | |
| 126 | void Directives::parse(String&& directives) { |
| 127 | if (directives.empty()) { |
| 128 | m_shared.reset(); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | List<Entry> entries; |
| 133 | StringView view(directives); |
| 134 | view.forEachSplitView("?", [&](StringView split, size_t beg, size_t end) { |
| 135 | if (!split.empty()) { |
| 136 | ImageOperation operation = NullImageOperation(); |
| 137 | if (beg == 0) { |
| 138 | try |
| 139 | { operation = imageOperationFromString(split); } |
| 140 | catch (StarException const& e) |
| 141 | { operation = ErrorImageOperation{std::exception_ptr()}; } |
| 142 | } |
| 143 | entries.emplace_back(std::move(operation), beg, end); |
| 144 | } |
| 145 | }); |
| 146 | |
| 147 | if (entries.empty()) { |
| 148 | m_shared.reset(); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | m_shared = std::make_shared<Shared const>(std::move(entries), std::move(directives)); |
| 153 | if (view.utf8().size() < 1000) { // Pre-load short enough directives |
| 154 | for (auto& entry : m_shared->entries) |
| 155 | entry.loadOperation(*m_shared); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | StringView Directives::prefix() const { |
| 160 | if (!m_shared) |
no test coverage detected