From 4119461f8e6912e0b79aac186dc7647212a8f6ab Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 18 Mar 2021 16:26:56 +0100 Subject: [PATCH] fixed: when reading a non-escaped space token we should check whether a delimiter was escaped or not also a '#' was not tested --- space/space.h | 2 +- space/spaceparser.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/space/space.h b/space/space.h index c19e7f3..8647527 100644 --- a/space/space.h +++ b/space/space.h @@ -674,7 +674,7 @@ protected: if( !is_main_object ) { str << '{'; - print_if(pretty_print, str, '\n'); + print_if(pretty_print && (!value.value_object.empty() || (child_spaces && !child_spaces->empty())), str, '\n'); } bool is_first = true; diff --git a/space/spaceparser.cpp b/space/spaceparser.cpp index d867cf6..09bd6b6 100644 --- a/space/spaceparser.cpp +++ b/space/spaceparser.cpp @@ -739,7 +739,7 @@ void SpaceParser::SkipWhite() { if( parsing_space ) { - while( IsWhite(lastc) || lastc == '#' ) + while( IsWhite(lastc) || (!char_was_escaped && lastc == '#') ) { if( lastc == '#' ) SkipLine(); @@ -808,7 +808,7 @@ void SpaceParser::ReadTokenUntilDelimiter(std::wstring & token, int delimiter1, { token.clear(); - while( lastc != -1 && lastc != '\n' && lastc != '#' && lastc != delimiter1 && lastc != delimiter2 ) + while( lastc != -1 && (char_was_escaped || (lastc != '\n' && lastc != '#' && lastc != delimiter1 && lastc != delimiter2)) ) { token += static_cast(lastc); ReadChar(); @@ -860,7 +860,7 @@ void SpaceParser::ReadSpaceFieldToken(std::wstring & token) { token.clear(); - while( lastc != -1 && (char_was_escaped || (lastc != separator && lastc != 10 && lastc != space_start)) ) + while( lastc != -1 && (char_was_escaped || (lastc != separator && lastc != 10 && lastc != space_start && lastc != '#' )) ) { token += static_cast(lastc); ReadChar(); @@ -915,7 +915,10 @@ void SpaceParser::ReadMultilineTokenQuoted(std::wstring & token) } - +/* + * this method is used to read the field name (key) in an object + * or to read the space child name (used in Space format) + */ void SpaceParser::ReadKey() { SkipWhite(); @@ -1128,7 +1131,7 @@ int SpaceParser::ReadChar() case 'b': lastc = 0x08; break; case 'f': lastc = 0x0c; break; case 'u': ReadUnicodeCodePoint(); break; - // in other cases we return the last character + // "in other cases we return the last character, so two \\ returns one \ " } }