18#include "pw_log_tokenized/config.h"
19#include "pw_status/status_with_size.h"
21namespace pw::log_tokenized {
39template <
typename Function>
41 std::string_view
string,
43 std::string_view field_prefix = PW_LOG_TOKENIZED_FIELD_PREFIX,
44 std::string_view key_val_separator = PW_LOG_TOKENIZED_KEY_VALUE_SEPARATOR) {
45 size_t fields_parsed = 0;
46 if (
string.empty() ||
string.find(field_prefix) != 0) {
51 for (
size_t key_start = field_prefix.size(); key_start <
string.size();
52 key_start = value_end + field_prefix.size()) {
53 const size_t key_end =
string.find(key_val_separator, key_start);
54 if (key_end == std::string_view::npos) {
55 return StatusWithSize::DataLoss(fields_parsed);
58 const size_t value_start = key_end + key_val_separator.size();
59 value_end =
string.find(field_prefix, value_start);
60 if (value_end == std::string_view::npos) {
61 value_end =
string.size();
64 field_consumer(
string.substr(key_start, key_end - key_start),
65 string.substr(value_start, value_end - value_start));
Definition: status_with_size.h:49
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
constexpr StatusWithSize ParseFields(std::string_view string, Function field_consumer, std::string_view field_prefix=PW_LOG_TOKENIZED_FIELD_PREFIX, std::string_view key_val_separator=PW_LOG_TOKENIZED_KEY_VALUE_SEPARATOR)
Definition: fields.h:40