]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/blob - stringoper.h
Updated Makefile not all llvm libraries are necessary. The program is now able to...
[boost-statechart-viewer.git] / stringoper.h
1 #include <string>
2
3 std::string get_line_of_code(const char* code) //return the line of code
4 {
5         std::string ret = code; 
6         int i;  
7         for(i = 0;i<ret.length();i++)
8         {
9                 if(ret[i]=='\n') break;
10         }       
11         return ret.substr(0,i);
12
13
14 std::string cut_commentary(const std::string line) //cut commentary at the end of line
15 {
16         int i = 0;
17         for(i = 0;i<line.length()-1;i++)
18         {
19                 if(line[i]=='/' && line[i+1]=='/') return line.substr(0,i);
20                 if(line[i]=='/' && line[i+1]=='*') return line.substr(0,i);
21         }
22         return line;
23
24 }
25
26 bool is_derived(const std::string line) // return true if the struct or class is derived
27 {
28         int i = 0;
29         for(i = 0;i<line.length()-1;i++)
30         {
31                 if(line[i]==':')
32                 {
33                         if(line[i+1]!=':') return true;
34                         else i+=1;
35                 }
36         }
37         return false;
38 }
39
40 std::string get_super_class(const std::string line) // get the super class of this declarations
41 {
42         int i = 0;
43         for(i = 0;i<line.length()-1;i++)
44         {
45                 if(line[i]==':')
46                 {
47                         if(line[i+1]!=':') break;
48                         else i+=1;
49                 }
50         }
51         return line.substr(i+1);
52 }
53
54 std::string clean_spaces(const std::string line)
55 {
56         int i;
57         std::string new_line = "";
58         for(i = 0;i<line.length();i++)
59         {
60                 if(!isspace(line[i])) new_line+=line[i];
61         }
62         //std::cout<<new_line;
63         return new_line;
64 }
65
66 bool is_state(const std::string line)
67 {
68         int pos = line.find("::");
69         if(pos==10)
70         {
71                 if(line.compare(0,24,"statechart::simple_state")==0)
72                 {
73                         return true;    
74                 }
75                 else
76                 {
77                         std::string str = line.substr(pos+2);
78                         if(str.compare(0,12,"simple_state")==0)return true;
79                 }
80         }
81         else
82         {
83                 std::string str = line.substr(pos+2);
84                 //std::cout<<str;
85                 if(str.compare(0,12,"simple_state")==0)return true;
86         }
87         return false;
88 }
89 // Transitions
90 std::string cut_typedef(std::string line) // cut typedef from the beginning
91 {
92         if(line.compare(0,8,"typedef ")==0)
93         {
94                 return line.substr(8);
95         }
96         else return line;       
97 }
98
99 int count(std::string line) //count all < in string
100 {
101         int number = 0;
102         for(int i = 0;i<line.length();i++)
103         {
104                 if(line[i]=='<') number+=1;
105         }
106         return number;
107 }
108
109 bool is_transition(const std::string line)
110 {
111         int pos = line.find("::");
112         if(pos==10)
113         {
114                 if(line.compare(0,22,"statechart::transition")==0)
115                 {
116                         return true;    
117                 }
118                 else
119                 {
120                         std::string str = line.substr(pos+2);
121                         if(str.compare(0,10,"transition")==0)return true;
122                 }
123         }
124         else
125         {
126                 std::string str = line.substr(pos+2);
127                 //std::cout<<str;
128                 if(str.compare(0,10,"transition")==0)return true;
129         }
130         return false;
131 }
132
133 std::string get_transition_params(std::string line)
134 {
135         int pos_front = line.find("<")+1;
136         int pos_end = line.find(">");
137         std::string first[2];
138         std::string params;
139         params = line.substr(pos_front,pos_end-pos_front);
140         return params;
141         
142 }
143