Browse Source

Add function Name() to generate name from template.

template_comparator
Michael Uleysky 8 years ago
parent
commit
9f323de184
  1. 29
      modules/gmt/cmpstr_alt.c++

29
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 "<<st.Name()<<std::endl;
// Dump code
{

Loading…
Cancel
Save