summaryrefslogtreecommitdiff
path: root/tools/inspect/unnamed_namespace_check.cpp
blob: 92431a171c50a12bef3eb527be1ab676176f9c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//  unnamed_namespace_check -----------------------------------------//

//  Copyright Gennaro Prota 2006.
//
//  Distributed under the Boost Software License, Version 1.0.
//  (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "unnamed_namespace_check.hpp"


namespace
{

  boost::regex unnamed_namespace_regex(
     "\\<namespace\\s*(\\?\\?<|\\{)" // trigraph ??< or {
  );

} // unnamed namespace (ironical? :-)



namespace boost
{
  namespace inspect
  {
   unnamed_namespace_check::unnamed_namespace_check() : m_errors(0)
   {
     register_signature( ".h" );
     register_signature( ".hh" ); // just in case
     register_signature( ".hpp" );
     register_signature( ".hxx" ); // just in case
     register_signature( ".inc" );
     register_signature( ".ipp" );
     register_signature( ".inl" );
   }

   void unnamed_namespace_check::inspect(
      const string & library_name,
      const path & full_path,   // example: c:/foo/boost/filesystem/path.hpp
      const string & contents )     // contents of file to be inspected
    {
      if (contents.find( "boostinspect:" "nounnamed" ) != string::npos) return;


      boost::sregex_iterator cur(contents.begin(), contents.end(), unnamed_namespace_regex), end;
      for( ; cur != end; ++cur, ++m_errors )
      {
        const string::size_type
         ln = std::count( contents.begin(), (*cur)[0].first, '\n' ) + 1;

        error( library_name, full_path, "Unnamed namespace", ln );
      }


    }
  } // namespace inspect
} // namespace boost