From 9f323de18457b3e3e64cda6d643480949910b8d1 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Thu, 29 Sep 2016 16:53:58 +1000 Subject: [PATCH] Add function Name() to generate name from template. --- modules/gmt/cmpstr_alt.c++ | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/gmt/cmpstr_alt.c++ b/modules/gmt/cmpstr_alt.c++ index bc9cdda..257ae0d 100644 --- a/modules/gmt/cmpstr_alt.c++ +++ b/modules/gmt/cmpstr_alt.c++ @@ -142,6 +142,34 @@ bool CmpStrEx(const std::string& expr, const std::string& str) State(const std::string& str):root(Parse(str)),s(str) {InitCursors(root.get());} + std::string Name() const + { + const struct Block* b=root.get(); + std::string res; + while(true) + { + // Processing current block + switch(b->type) + { + case(Block::TEXT): {res+=s.substr(b->b,b->e-b->b); break;} + case(Block::OPTIONAL): {b=b->child.get(); goto next;} + case(Block::VARIANTS): {b=b->child.get(); goto next;} + case(Block::DELIM): {b=b->parent; break;} + default: {} + } + // Go to next block + while(true) + { + if(nullptr!=b->next) {b=b->next.get(); goto next;} + if(nullptr!=b->parent) b=b->parent; + else break; + } + if(nullptr==b->next && nullptr==b->parent) break; + next: ; + } + return res; + } + bool CmpSmb(const char c) { @@ -197,6 +225,7 @@ bool CmpStrEx(const std::string& expr, const std::string& str) // Main function struct State st(expr); + std::cout<<"Name is "<