1 // minmax_check implementation --------------------------------------------//
3 // Copyright Beman Dawes 2002.
4 // Copyright Gennaro Prota 2006.
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
13 #include "minmax_check.hpp"
14 #include "boost/regex.hpp"
15 #include "boost/lexical_cast.hpp"
19 boost::regex
minmax_regex(
21 "^\\s*#\\s*undef\\s*" // # undef
22 "\\b(min|max)\\b" // followed by min or max, whole word
26 "//[^\\n]*" // single line comments (//)
28 "/\\*.*?\\*/" // multi line comments (/**/)
30 "\"(?:\\\\\\\\|\\\\\"|[^\"])*\"" // string literals
34 "\\b(min|max)\\b" // min or max, whole word
35 "\\s*\\(" // followed by 0 or more spaces and an opening paren
37 , boost::regex::normal
);
39 } // unnamed namespace
46 // minmax_check constructor -------------------------------------------//
48 minmax_check::minmax_check()
51 // C/C++ source code...
52 register_signature( ".c" );
53 register_signature( ".cpp" );
54 register_signature( ".cxx" );
55 register_signature( ".h" );
56 register_signature( ".hpp" );
57 register_signature( ".hxx" );
58 register_signature( ".inc" );
59 register_signature( ".ipp" );
62 // inspect ( C++ source files ) ---------------------------------------//
64 void minmax_check::inspect(
65 const string
& library_name
,
66 const path
& full_path
, // example: c:/foo/boost/filesystem/path.hpp
67 const string
& contents
) // contents of file to be inspected
69 if (contents
.find( "boostinspect:" "nominmax" ) != string::npos
) return;
71 boost::sregex_iterator
cur(contents
.begin(), contents
.end(), minmax_regex
), end
;
73 for( ; cur
!= end
; ++cur
/*, ++m_errors*/ )
76 if(!(*cur
)[3].matched
)
78 string::const_iterator it
= contents
.begin();
79 string::const_iterator match_it
= (*cur
)[0].first
;
81 string::const_iterator line_start
= it
;
83 string::size_type line_number
= 1;
84 for ( ; it
!= match_it
; ++it
) {
85 if (string::traits_type::eq(*it
, '\n')) {
87 line_start
= it
+ 1; // could be end()
92 error( library_name
, full_path
, string(name())
93 + " violation of Boost min/max guidelines on line "
94 + boost::lexical_cast
<string
>( line_number
) );
100 } // namespace inspect