LifeV
minmax_check.cpp
Go to the documentation of this file.
1 // minmax_check implementation -----------------------------------------------//
2 
3 // Copyright Beman Dawes 2002.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 #include "minmax_check.hpp"
9 #include <boost/regex.hpp>
10 #include <boost/lexical_cast.hpp>
11 
12 namespace
13 {
14 boost::regex minmax_regex (
15  "\\b(min|max)\\b" // match min or max, whole word
16  "\\s*\\(", // followed by 0 or more spaces and an opening paren
17  boost::regex::normal);
18 
19 } // unnamed namespace
20 
21 namespace boost
22 {
23 namespace inspect
24 {
25 
26 // minmax_check constructor --------------------------------------------------//
27 
29  : m_errors (0)
30 {
31  // C/C++ source code...
32  register_signature ( ".c" );
33  register_signature ( ".cpp" );
34  register_signature ( ".cxx" );
35  register_signature ( ".h" );
36  register_signature ( ".hpp" );
37  register_signature ( ".hxx" );
38  register_signature ( ".inc" );
39  register_signature ( ".ipp" );
40 }
41 
42 // inspect ( C++ source files ) ----------------------------------------------//
43 
44 void minmax_check::inspect (
45  const string& library_name,
46  const path& full_path, // example: c:/foo/boost/filesystem/path.hpp
47  const string& contents) // contents of file to be inspected
48 {
49  boost::sregex_iterator cur (contents.begin(), contents.end(), minmax_regex), end;
50 
51  for ( ; cur != end; ++cur, ++m_errors )
52  {
53  std::string linenbr = std::to_string (
54  std::count ( contents.begin(), (*cur) [0].first, '\n' ) + 1);
55 
56  error ( library_name, full_path, "violation of Boost min/max guidelines on line " + linenbr );
57  }
58 }
59 
60 } // namespace inspect
61 } // namespace boost
boost::regex minmax_regex("\(min|max)\" "\*\", boost::regex::normal)