snip5.cpp

来自「正则表达式源代码」· C++ 代码 · 共 52 行

CPP
52
字号
/* * * Copyright (c) 1998-2000 * Dr John Maddock * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation.  Dr John Maddock makes no representations * about the suitability of this software for any purpose. * It is provided "as is" without express or implied warranty. * */#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'stypedef 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);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?