| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <boost/regex.hpp> |
| #include <string> |
| #include <map> |
| #include <fstream> |
| #include <iostream> |
|
|
| using namespace std; |
|
|
| |
| |
| |
| |
|
|
| typedef std::map<std::string, std::string::difference_type, std::less<std::string> > map_type; |
|
|
| const char* re = |
| |
| "^[[:space:]]*" |
| |
| "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?" |
| |
| "(class|struct)[[:space:]]*" |
| |
| "(" |
| "\\<\\w+\\>" |
| "(" |
| "[[:blank:]]*\\([^)]*\\)" |
| ")?" |
| "[[:space:]]*" |
| ")*" |
| |
| "(\\<\\w*\\>)[[:space:]]*" |
| |
| "(<[^;:{]+>)?[[:space:]]*" |
| |
| "(\\{|:[^;\\{()]*\\{)"; |
|
|
|
|
| boost::regex expression(re); |
| map_type class_index; |
|
|
| bool regex_callback(const boost::match_results<std::string::const_iterator>& what) |
| { |
| |
| |
| |
| |
| class_index[what[5].str() + what[6].str()] = what.position(5); |
| return true; |
| } |
|
|
| void load_file(std::string& s, std::istream& is) |
| { |
| s.erase(); |
| if(is.bad()) return; |
| s.reserve(static_cast<std::string::size_type>(is.rdbuf()->in_avail())); |
| char c; |
| while(is.get(c)) |
| { |
| if(s.capacity() == s.size()) |
| s.reserve(s.capacity() * 3); |
| s.append(1, c); |
| } |
| } |
|
|
| int main(int argc, const char** argv) |
| { |
| std::string text; |
| for(int i = 1; i < argc; ++i) |
| { |
| cout << "Processing file " << argv[i] << endl; |
| std::ifstream fs(argv[i]); |
| load_file(text, fs); |
| fs.close(); |
| |
| boost::sregex_iterator m1(text.begin(), text.end(), expression); |
| boost::sregex_iterator m2; |
| std::for_each(m1, m2, ®ex_callback); |
| |
| cout << class_index.size() << " matches found" << endl; |
| map_type::iterator c, d; |
| c = class_index.begin(); |
| d = class_index.end(); |
| while(c != d) |
| { |
| cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl; |
| ++c; |
| } |
| class_index.erase(class_index.begin(), class_index.end()); |
| } |
| return 0; |
| } |
|
|
|
|
|
|
|
|