blob: 230c67764928febac19f861af5f4b0aa0b7f8dd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
|