]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/blob - src/stringoper.h
c4ca4e20e6b3a0b7a5ff975c7b2eedd3df606876
[boost-statechart-viewer.git] / src / stringoper.h
1 #include <string>
2
3 std::string get_line_of_code(const std::string code) //return the line of code
4 {
5         std::string ret = code; 
6         int i;  
7         //std::cout<<code<<"\n\n";
8         for(i = 0;i<ret.length();i++)
9         {
10                 if(ret[i]=='\n'||ret[i]=='{') break;
11         }       
12         return ret.substr(0,i);
13
14
15 std::string cut_commentary(const std::string line) //cut commentary at the end of line
16 {
17         int i = 0;
18         for(i = 0;i<line.length()-1;i++)
19         {
20                 if(line[i]=='/' && line[i+1]=='/') return line.substr(0,i);
21                 if(line[i]=='/' && line[i+1]=='*') return line.substr(0,i);
22         }
23         return line;
24
25 }
26
27 std::string cut_namespaces(std::string line) //cut namespaces from the name of the state
28 {
29         int i = line.rfind("::");
30         if(i==-1) return line;
31         return line.substr(i+2);
32 }
33
34 bool is_derived(const std::string line) // return true if the struct or class is derived
35 {
36         int i = 0;
37         for(i = 0;i<line.length()-1;i++)
38         {
39                 if(line[i]==':')
40                 {
41                         if(line[i+1]!=':') return true;
42                         else i+=1;
43                 }
44         }
45         return false;
46 }
47
48 std::string get_super_class(const std::string line) // get the super class of this declarations
49 {
50         int i = 0;
51         for(i = 0;i<line.length()-1;i++)
52         {
53                 if(line[i]==':')
54                 {
55                         if(line[i+1]!=':') break;
56                         else i+=1;
57                 }
58         }
59         return line.substr(i+1);
60 }
61
62 std::string get_next_base(const std::string line) // get the super class of this declarations
63 {
64         int i = 0;
65         int brackets = 0;
66         for(i = 0;i<line.length()-1;i++)
67         {
68                 if(line[i]=='<') brackets+=1;
69                 if(line[i]=='>') brackets-=1;
70                 if(line[i]==',' && brackets == 0) break;
71         }
72         return line.substr(i+1);
73 }  
74
75 std::string get_first_base(const std::string line) // get the super class of this declarations
76 {
77         int i = 0;
78         int brackets = 0;
79         for(i = 0;i<line.length()-1;i++)
80         {
81                 if(line[i]=='<') brackets+=1;
82                 if(line[i]=='>') brackets-=1;
83                 if(line[i]==',' && brackets == 0) break;
84         }
85         return line.substr(0,i);
86 }  
87
88
89 std::string clean_spaces(const std::string line)
90 {
91         int i;
92         std::string new_line = "";
93         for(i = 0;i<line.length();i++)
94         {
95                 if(!isspace(line[i])) new_line+=line[i];
96         }
97         //std::cout<<new_line;
98         return new_line;
99 }
100
101 bool is_state(const std::string line)
102 {
103         int pos = line.find("::");
104         if(pos == 5)
105         {
106                 if(line.compare(0,31,"boost::statechart::simple_state")==0)
107                 {
108                         return true;    
109                 }
110                 else
111                 {
112                         return false;
113                 }
114         }
115         else
116         {
117                 if(line.compare(0,24,"statechart::simple_state")==0)
118                 {
119                         return true;    
120                 }
121                 else
122                 {
123                         return false;
124                 }
125         }
126 }
127 // Transitions
128 std::string cut_typedef(std::string line) // cut typedef from the beginning
129 {
130         if(line.compare(0,8,"typedef ")==0)
131         {
132                 return line.substr(8);
133         }
134         else return line;       
135 }
136
137 int count(std::string line) //count all < in string
138 {
139         int number = 0;
140         for(int i = 0;i<line.length();i++)
141         {
142                 if(line[i]=='<') number+=1;
143         }
144         return number;
145 }
146
147 bool is_list(const std::string line)
148 {
149         int pos = line.find("::");
150         if(pos == 5)
151         {
152                 if(line.compare(0,16,"boost::mpl::list")==0)
153                 {
154                         return true;    
155                 }
156                 else
157                 {
158                         return false;
159                 }
160         }
161         if(line.compare(0,9,"mpl::list")==0)
162         {
163                 return true;    
164         }
165         else
166         {
167                 return false;
168         }
169 }
170
171 std::string get_inner_part(const std::string line)
172 {
173         std::string str;
174         int i, pos = 0;
175         for(i = 0;i<line.length();i++)
176         {
177                 if(line[i]=='<') break;
178         }
179         str = line.substr(i+1);
180         for(i = 0;i<str.length();i++)
181         {
182                 if(str[i]=='<') pos+=1;
183                 if(str[i]=='>')
184                 { 
185                         if(pos==0) break;
186                         else pos-=1;
187                 }
188         }
189         //std::cout<<str.substr(0,i);
190         return str.substr(0,i);
191 }
192
193 bool is_transition(const std::string line)
194 {
195         int pos = line.find("::");
196         if(pos == 5)
197         {
198                 if(line.compare(0,29,"boost::statechart::transition")==0)
199                 {
200                         return true;    
201                 }
202                 else
203                 {
204                         return false;
205                 }
206         }
207         else
208         {       
209                 if(line.compare(0,22,"statechart::transition")==0)
210                 {
211                         return true;    
212                 }
213                 else
214                 {
215                         return false;
216                 }
217         }
218 }
219
220 std::string get_params(std::string line)
221 {
222         int pos_front = line.find("<")+1;
223         int pos_end = line.find(">");
224         std::string params;
225         params = line.substr(pos_front,pos_end-pos_front);
226         return params;
227         
228 }
229
230 bool is_machine(const std::string line)
231 {
232         int pos = line.find("::");
233         if(pos == 5)
234         {
235                 if(line.compare(0,32,"boost::statechart::state_machine")==0)
236                 {
237                         return true;    
238                 }
239                 else
240                 {
241                         return false;
242                 }
243         }
244         else
245         {       
246                 if(line.compare(0,25,"statechart::state_machine")==0)
247                 {
248                         return true;    
249                 }
250                 else
251                 {
252                         return false;
253                 }
254         }
255 }