diff options
Diffstat (limited to 'sax/src/sax_attributes.cc')
| -rw-r--r-- | sax/src/sax_attributes.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/sax/src/sax_attributes.cc b/sax/src/sax_attributes.cc new file mode 100644 index 0000000..230c677 --- /dev/null +++ b/sax/src/sax_attributes.cc @@ -0,0 +1,38 @@ +#include "sax_attributes.hh" + +namespace modxml { +namespace sax { + +Attribute::Attribute(std::string_view name, std::string_view value) + : name(name), value(value) {} + +std::optional<std::string_view> Attributes::find_first(std::string_view name) + const { + for (auto it = begin(); it != end(); ++it) { + if (it->name == name) + return it->value; + } + return std::nullopt; +} + +std::optional<std::string_view> Attributes::find_last(std::string_view name) + const { + for (size_t i = size(); i > 0; --i) { + auto const& a = at(i - 1); + if (a.name == name) + return a.value; + } + return std::nullopt; +} + +std::optional<std::size_t> Attributes::find(std::string_view name, + std::size_t index) const { + for (; index < size(); ++index) { + if (at(index).name == name) + return index; + } + return std::nullopt; +} + +} // namespace sax +} // namespace modxml |
