From df4a44274b7d0a062400f72d6393de881f797b86 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 22 Nov 2021 12:37:53 +0100 Subject: [PATCH] Added support for empty spaces within attribute names and double quotes --- radio/src/storage/yaml/yaml_parser.cpp | 26 ++++++++++++++++++-------- radio/src/storage/yaml/yaml_parser.h | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/radio/src/storage/yaml/yaml_parser.cpp b/radio/src/storage/yaml/yaml_parser.cpp index 92e601946..220f9cd4e 100644 --- a/radio/src/storage/yaml/yaml_parser.cpp +++ b/radio/src/storage/yaml/yaml_parser.cpp @@ -148,17 +148,24 @@ YamlParser::parse(const char* buffer, unsigned int size) } state = ps_Attr; + if (*c == '\"') { + state = ps_AttrQuo; + break; + } + CONCAT_STR(scratch_buf, scratch_len, *c); + break; + + case ps_AttrQuo: + if (*c == '\"') { + state = ps_Attr; + break; + } CONCAT_STR(scratch_buf, scratch_len, *c); break; case ps_Attr: - if (*c == ' ') {// assumes nothing else comes after spaces start - node_found = calls->find_node(ctx, scratch_buf, scratch_len); - if (!node_found) { - TRACE_YAML("YAML_PARSER: Could not find node '%.*s' (1)\n", - scratch_len, scratch_buf); - } - state = ps_AttrSP; + if (*c == '\"') { + state = ps_AttrQuo; break; } if ((*c != ':') && (*c != '\r') && (*c != '\n')) @@ -167,6 +174,7 @@ YamlParser::parse(const char* buffer, unsigned int size) case ps_AttrSP: if (*c == '\r' || *c == '\n') { if (state == ps_Attr) { + // TODO: trim spaces at the end? node_found = calls->find_node(ctx, scratch_buf, scratch_len); if (!node_found) { TRACE_YAML("YAML_PARSER: Could not find node '%.*s' (2)\n", @@ -179,6 +187,7 @@ YamlParser::parse(const char* buffer, unsigned int size) } if (*c == ':') { if (state == ps_Attr) { + // TODO: trim spaces at the end? node_found = calls->find_node(ctx, scratch_buf, scratch_len); if (!node_found) { TRACE_YAML("YAML_PARSER: Could not find node '%.*s' (3)\n", @@ -261,9 +270,10 @@ YamlParser::parse(const char* buffer, unsigned int size) return DONE_PARSING; case ps_Val: - if (*c == ' ' || *c == '\r' || *c == '\n') { + if (*c == '\r' || *c == '\n') { // set attribute if (node_found) { + // TODO: trim spaces at the end? calls->set_attr(ctx, scratch_buf, scratch_len); } saved_state = state; diff --git a/radio/src/storage/yaml/yaml_parser.h b/radio/src/storage/yaml/yaml_parser.h index 74b26db47..b3b32d1dc 100644 --- a/radio/src/storage/yaml/yaml_parser.h +++ b/radio/src/storage/yaml/yaml_parser.h @@ -42,6 +42,7 @@ class YamlParser ps_Indent=0, ps_Dash, ps_Attr, + ps_AttrQuo, ps_AttrSP, ps_Sep, ps_Val,