source: icGREP/icgrep-0.8/icgrep/printer_re.cpp @ 3972

Last change on this file since 3972 was 3850, checked in by cameron, 5 years ago

icgrep-0.8 distribution

File size: 2.9 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "printer_re.h"
8
9
10Printer_RE::Printer_RE(){}
11
12std::string Printer_RE::PrintRE(RE* re)
13{
14    std::string retVal = "";
15
16    if (Alt* re_alt = dynamic_cast<Alt*>(re))
17    {
18        retVal += "(Alt[";
19
20        std::list<RE*>::iterator it;
21        for (it = re_alt->GetREList()->begin(); it != re_alt->GetREList()->end(); ++it)
22        {
23            retVal += PrintRE(*it) + ",";
24        }
25        retVal = retVal.substr(0, retVal.size() - 1);
26        retVal += "])";
27    }
28    else if (CC* re_cc = dynamic_cast<CC*>(re))
29    {
30        retVal += "CC \"";
31        retVal += re_cc->getName();
32        retVal += "\" ";
33
34        std::vector<CharSetItem> items = re_cc->getItems();
35        std::vector<CharSetItem>::iterator it;
36        for (it = items.begin(); it != items.end(); ++it)
37        {
38            retVal += "[";
39            retVal += INT2STRING(it->lo_codepoint) + ",";
40            retVal += INT2STRING(it->hi_codepoint);
41            retVal += "]";
42        }
43
44        //std::string member = (re_cc->is_member(47) ? "True" : "False");
45        //retVal += " is codepoint 47 a member: " + member;
46
47        /*
48        retVal += "CC \"";
49        retVal += re_cc->getName();
50        retVal += "\" ";
51
52        retVal += " Removed: 100 ";
53        re_cc->remove1(100);
54        //re_cc->remove_range(40,50);
55
56        std::vector<CharSetItem> r_items = re_cc->getItems();
57        std::vector<CharSetItem>::iterator r_it;
58        for (r_it = r_items.begin(); r_it != r_items.end(); ++r_it)
59        {
60            retVal += "[";
61            retVal += INT2STRING(r_it->lo_codepoint) + ",";
62            retVal += INT2STRING(r_it->hi_codepoint);
63            retVal += "]";
64        }
65        */
66    }
67    else if (End* re_end = dynamic_cast<End*>(re))
68    {
69        retVal += "End";
70    }
71    else if (Rep* re_rep = dynamic_cast<Rep*>(re))
72    {
73        retVal += "Rep("  + PrintRE(re_rep->getRE()) + "," + INT2STRING(re_rep->getLB()) + ",";
74
75        if (Unbounded* unbounded = dynamic_cast<Unbounded*>(re_rep->getUB()))
76        {
77            retVal += "Unbounded)";
78        }
79        else if (UpperBound* upperbound = dynamic_cast<UpperBound*>(re_rep->getUB()))
80        {
81            retVal += "UpperBound " + INT2STRING(upperbound->getUB()) + ")";
82        }
83    }
84    else if (Seq* re_seq = dynamic_cast<Seq*>(re))
85    {
86        retVal += "(Seq[";
87        std::list<RE*>::iterator it;
88        for (it = re_seq->GetREList()->begin(); it != re_seq->GetREList()->end(); ++it)
89        {
90            retVal += PrintRE(*it) + ",";
91        }
92        retVal = retVal.substr(0, retVal.size() - 1);
93        retVal += "])";
94    }
95    else if (Start* re_start = dynamic_cast<Start*>(re))
96    {
97        retVal += "Start";
98    }
99    else
100    {
101        retVal += "--> RE Unknown <--";
102    }
103
104    return retVal;
105}
Note: See TracBrowser for help on using the repository browser.