From 7dd49c6293172b494c78918507242cdb55d35137 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 21 Jan 2024 12:31:30 +0100 Subject: WIP --- sax/src/sax_attributes.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sax/src/sax_attributes.cc (limited to 'sax/src/sax_attributes.cc') 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 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 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 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 -- cgit v1.2.3-70-g09d2