From 3a2d52121be3ba48e610240cba6ebfd8d1e55468 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 10 Oct 2018 17:38:40 +0200 Subject: [PATCH] string parsing and composing of unique objects --- alib2str/src/core/stringApi.hpp | 12 +++++++++++- alib2str/test-src/object/ObjectTest.cpp | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/alib2str/src/core/stringApi.hpp b/alib2str/src/core/stringApi.hpp index a8213b4335..2c63eb9a71 100644 --- a/alib2str/src/core/stringApi.hpp +++ b/alib2str/src/core/stringApi.hpp @@ -14,6 +14,7 @@ #include <alib/string> #include <alib/memory> #include <alib/algorithm> +#include <alib/istream> #include <object/Object.h> #include <object/AnyObject.h> @@ -108,7 +109,14 @@ public: if ( pos != input.tellg ( ) ) throw exception::CommonException ( "First function of registered callback moved the stream." ); - return callback->second->parse ( input ); + object::Object res = callback->second->parse ( input ); + + input.clear(); + while ( input >> ext::string ( "'" ) ) + ++ res; + input.clear(); + + return res; } static bool first ( std::istream & input ) { @@ -127,6 +135,8 @@ public: if ( callback == composeFunctions ( ).end ( ) ) throw exception::CommonException ( "Compose callback for " + type + " tag not registered." ); callback->second->compose ( output, data ); + for ( unsigned i = 0; i < data.getId ( ); ++ i ) + output << "'"; } }; diff --git a/alib2str/test-src/object/ObjectTest.cpp b/alib2str/test-src/object/ObjectTest.cpp index cac78af901..6fab410c50 100644 --- a/alib2str/test-src/object/ObjectTest.cpp +++ b/alib2str/test-src/object/ObjectTest.cpp @@ -15,7 +15,7 @@ void ObjectTest::tearDown() { } void ObjectTest::testComposing() { - std::string input = "(1, 2)"; + std::string input = "(1, 2)'"; object::Object label = factory::StringDataFactory::fromString (input); std::string output = factory::StringDataFactory::toString(label); -- GitLab