1 //  unnamed_namespace_check -----------------------------------------//
2 
3 //  Copyright Gennaro Prota 2006.
4 //
5 //  Distributed under the Boost Software License, Version 1.0.
6 //  (See accompanying file LICENSE_1_0.txt or copy at
7 //  http://www.boost.org/LICENSE_1_0.txt)
8 
9 #include "boost/regex.hpp"
10 #include "boost/lexical_cast.hpp"
11 #include "unnamed_namespace_check.hpp"
12 
13 
14 namespace
15 {
16 
17   boost::regex unnamed_namespace_regex(
18      "\\<namespace\\s*(\\?\\?<|\\{)" // trigraph ??< or {
19   );
20 
21 } // unnamed namespace (ironical? :-)
22 
23 
24 
25 namespace boost
26 {
27   namespace inspect
28   {
unnamed_namespace_check()29    unnamed_namespace_check::unnamed_namespace_check() : m_errors(0)
30    {
31      register_signature( ".h" );
32      register_signature( ".hh" ); // just in case
33      register_signature( ".hpp" );
34      register_signature( ".hxx" ); // just in case
35      register_signature( ".inc" );
36      register_signature( ".ipp" );
37      register_signature( ".inl" );
38    }
39 
inspect(const string & library_name,const path & full_path,const string & contents)40    void unnamed_namespace_check::inspect(
41       const string & library_name,
42       const path & full_path,   // example: c:/foo/boost/filesystem/path.hpp
43       const string & contents )     // contents of file to be inspected
44     {
45       if (contents.find( "boostinspect:" "nounnamed" ) != string::npos) return;
46 
47 
48       boost::sregex_iterator cur(contents.begin(), contents.end(), unnamed_namespace_regex), end;
49       for( ; cur != end; ++cur, ++m_errors )
50       {
51         const string::size_type
52          ln = std::count( contents.begin(), (*cur)[0].first, '\n' ) + 1;
53 
54         error( library_name, full_path, "Unnamed namespace", ln );
55       }
56 
57 
58     }
59   } // namespace inspect
60 } // namespace boost
61 
62 
63