6 #include "opentelemetry/common/key_value_iterable_view.h"
7 #include "opentelemetry/common/string_util.h"
8 #include "opentelemetry/nostd/function_ref.h"
9 #include "opentelemetry/nostd/string_view.h"
10 #include "opentelemetry/nostd/unique_ptr.h"
11 #include "opentelemetry/version.h"
15 #include <type_traits>
22 struct KeyValueStringTokenizerOptions
30 class KeyValueStringTokenizer
36 : str_(str), opts_(opts), index_(0)
41 static std::string default_str =
"";
53 while (index_ < str_.
size())
55 bool is_empty_pair =
false;
57 if (
end == std::string::npos)
61 else if (
end == index_)
71 if (list_member.size() == 0 || is_empty_pair)
74 index_ =
end + 2 - is_empty_pair;
87 if (key_end_pos == std::string::npos)
94 key = list_member.substr(0, key_end_pos);
95 value = list_member.substr(key_end_pos + 1);
110 size_t cnt = 0, begin = 0;
111 while (begin < str_.
size())
115 if (
end == std::string::npos)
127 void reset() noexcept { index_ = 0; }
136 class KeyValueProperties
143 Entry() : key_(nullptr), value_(nullptr) {}
148 key_ = CopyStringToPointer(copy.key_.get());
149 value_ = CopyStringToPointer(copy.value_.get());
155 key_ = CopyStringToPointer(other.key_.get());
156 value_ = CopyStringToPointer(other.value_.get());
167 key_ = CopyStringToPointer(key);
168 value_ = CopyStringToPointer(value);
189 char *temp =
new char[str.
size() + 1];
190 memcpy(temp, str.
data(), str.
size());
191 temp[str.
size()] =
'\0';
215 template <class T, class = typename std::enable_if<detail::is_key_value_iterable<T>::value>::type>
221 for (
auto &e : keys_and_values)
223 Entry entry(e.first, e.second);
233 Entry entry(key, value);
245 if (!callback(entry.GetKey(), entry.GetValue()))
259 if (entry.GetKey() == key)
261 const auto &entry_value = entry.GetValue();
262 value = std::string(entry_value.data(), entry_value.size());