diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-16 11:03:27 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2015-02-16 11:03:27 +0100 |
commit | 235b8ce21d6a24f01e73ed745f32487553b6d231 (patch) | |
tree | a5f9ccb5d3169d64e8b51faea1f773702e70f668 /src/core/common | |
parent | 884c7d772da6ad9869866f8a7a15bd08a15376ba (diff) |
Fixed bug #61 and added unit test
Diffstat (limited to 'src/core/common')
-rw-r--r-- | src/core/common/VariantReader.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
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<bool, Variant> VariantReader::parseGenericToken( std::pair<bool, Variant> 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<bool, Variant> res = - parseGenericToken(reader, loggerFork, std::unordered_set<char>{}, true); + // Try to parse a single token + std::pair<bool, Variant> res = parseGenericToken( + reader, loggerFork, std::unordered_set<char>{}, 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 |