summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSune Vuorela <sune@vuorela.dk>2023-03-27 11:11:24 +0200
committerSune Vuorela <sune@vuorela.dk>2023-05-21 15:07:41 +0200
commit266a2fd0a8cce584e0ffad0bc06670ed7136fc19 (patch)
tree4bcec9285a83ba7ecf0fde95aa123c20b81eeaa4
parent395a5b7e5a8efa049a0eb3a4bbff41737aaf5fc1 (diff)
Add function to get specific element from the DN parse result
-rw-r--r--poppler/DistinguishedNameParser.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/poppler/DistinguishedNameParser.h b/poppler/DistinguishedNameParser.h
index 1fef597d..dfabc97e 100644
--- a/poppler/DistinguishedNameParser.h
+++ b/poppler/DistinguishedNameParser.h
@@ -20,6 +20,7 @@
#include <string>
#include <utility>
#include <optional>
+#include <algorithm>
namespace DN {
namespace detail {
@@ -306,6 +307,15 @@ static Result parseString(std::string_view string)
return result;
}
+/// returns the first value of a given key (note. there can be multiple)
+/// or nullopt if key is not available
+inline std::optional<std::string> FindFirstValue(const Result &dn, std::string_view key)
+{
+ auto first = std::find_if(dn.begin(), dn.end(), [&key](const auto &it) { return it.first == key; });
+ if (first == dn.end()) {
+ return {};
+ }
+ return first->second;
}
-
+} // namespace DN
#endif // DISTINGUISHEDNAMEPARSER_H