]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/inspect/minmax_check.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / inspect / minmax_check.cpp
1 // minmax_check implementation --------------------------------------------//
2
3 // Copyright Beman Dawes 2002.
4 // Copyright Gennaro Prota 2006.
5 //
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)
9
10
11 #include <algorithm>
12
13 #include "minmax_check.hpp"
14 #include "boost/regex.hpp"
15 #include "boost/lexical_cast.hpp"
16
17 namespace
18 {
19 boost::regex minmax_regex(
20 "("
21 "^\\s*#\\s*undef\\s*" // # undef
22 "\\b(min|max)\\b" // followed by min or max, whole word
23 ")"
24 "|" // or (ignored)
25 "("
26 "//[^\\n]*" // single line comments (//)
27 "|"
28 "/\\*.*?\\*/" // multi line comments (/**/)
29 "|"
30 "\"(?:\\\\\\\\|\\\\\"|[^\"])*\"" // string literals
31 ")"
32 "|" // or
33 "("
34 "\\b(min|max)\\b" // min or max, whole word
35 "\\s*\\(" // followed by 0 or more spaces and an opening paren
36 ")"
37 , boost::regex::normal);
38
39 } // unnamed namespace
40
41 namespace boost
42 {
43 namespace inspect
44 {
45
46 // minmax_check constructor -------------------------------------------//
47
48 minmax_check::minmax_check()
49 : m_errors(0)
50 {
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" );
60 }
61
62 // inspect ( C++ source files ) ---------------------------------------//
63
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
68 {
69 if (contents.find( "boostinspect:" "nominmax" ) != string::npos) return;
70
71 boost::sregex_iterator cur(contents.begin(), contents.end(), minmax_regex), end;
72
73 for( ; cur != end; ++cur /*, ++m_errors*/ )
74 {
75
76 if(!(*cur)[3].matched)
77 {
78 string::const_iterator it = contents.begin();
79 string::const_iterator match_it = (*cur)[0].first;
80
81 string::const_iterator line_start = it;
82
83 string::size_type line_number = 1;
84 for ( ; it != match_it; ++it) {
85 if (string::traits_type::eq(*it, '\n')) {
86 ++line_number;
87 line_start = it + 1; // could be end()
88 }
89 }
90
91 ++m_errors;
92 error( library_name, full_path, string(name())
93 + " violation of Boost min/max guidelines on line "
94 + boost::lexical_cast<string>( line_number ) );
95 }
96
97 }
98 }
99
100 } // namespace inspect
101 } // namespace boost
102