mirror of
https://github.com/boostorg/regex.git
synced 2025-07-03 23:56:34 +02:00
37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
![]() |
#include <string>
|
||
|
#include <map>
|
||
|
#include <regex>
|
||
|
|
||
|
// purpose:
|
||
|
// takes the contents of a file in the form of a string
|
||
|
// and searches for all the C++ class definitions, storing
|
||
|
// their locations in a map of strings/int's
|
||
|
|
||
|
typedef std::map<std::string, int, std::less<std::string> > map_type;
|
||
|
|
||
|
regex expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>[[:space:]]*)?(\\{|:[^;\\{()]*\\{)");
|
||
|
map_type class_index;
|
||
|
std::string::const_iterator base;
|
||
|
|
||
|
bool grep_callback(const reg_match<std::string::const_iterator, regex::alloc_type>& what)
|
||
|
{
|
||
|
// what[0] contains the whole string
|
||
|
// what[5] contains the class name.
|
||
|
// what[6] contains the template specialisation if any.
|
||
|
// add class name and position to map:
|
||
|
class_index[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] =
|
||
|
what[5].first - base;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void IndexClasses(const std::string& file)
|
||
|
{
|
||
|
std::string::const_iterator start, end;
|
||
|
start = file.begin();
|
||
|
end = file.end();
|
||
|
base = start;
|
||
|
reg_grep(grep_callback, start, end, expression, match_default);
|
||
|
}
|
||
|
|
||
|
|