From 235b8ce21d6a24f01e73ed745f32487553b6d231 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Mon, 16 Feb 2015 11:03:27 +0100 Subject: Fixed bug #61 and added unit test --- src/core/common/VariantReader.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/core/common/VariantReader.cpp') diff --git a/src/core/common/VariantReader.cpp b/src/core/common/VariantReader.cpp index fb93ad0..601d086 100644 --- a/src/core/common/VariantReader.cpp +++ b/src/core/common/VariantReader.cpp @@ -848,17 +848,23 @@ std::pair VariantReader::parseGenericToken( std::pair VariantReader::parseGenericString( const std::string &str, Logger &logger, SourceId sourceId, size_t offs) { - CharReader reader{str, sourceId, offs}; - LoggerFork loggerFork = logger.fork(); + // If the given string is empty, just return it as a string (there is no + // other type for which something empty would be valid) + // TODO: How to integrate this into parseGenericToken? + if (!str.empty()) { + CharReader reader{str, sourceId, offs}; + LoggerFork loggerFork = logger.fork(); - // Try to parse a single token - std::pair res = - parseGenericToken(reader, loggerFork, std::unordered_set{}, true); + // Try to parse a single token + std::pair res = parseGenericToken( + reader, loggerFork, std::unordered_set{}, true); - // If the string was actually consisted of a single token, return that token - if (reader.atEnd()) { - loggerFork.commit(); - return res; + // If the string was actually consisted of a single token, return that + // token + if (reader.atEnd()) { + loggerFork.commit(); + return res; + } } // Otherwise return the given string as a string, set the location of the -- cgit v1.2.3