1 // end_check implementation -------------------------------------------------// 2 3 // Copyright Beman Dawes 2002. 4 // Copyright Daniel James 2009. 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 #include "end_check.hpp" 11 #include <boost/next_prior.hpp> 12 13 namespace boost 14 { 15 namespace inspect 16 { end_check()17 end_check::end_check() : m_files_with_errors(0) 18 { 19 register_signature( ".c" ); 20 register_signature( ".cpp" ); 21 register_signature( ".cxx" ); 22 register_signature( ".h" ); 23 register_signature( ".hpp" ); 24 register_signature( ".hxx" ); 25 register_signature( ".ipp" ); 26 } 27 inspect(const string & library_name,const path & full_path,const string & contents)28 void end_check::inspect( 29 const string & library_name, 30 const path & full_path, // example: c:/foo/boost/filesystem/path.hpp 31 const string & contents ) // contents of file to be inspected 32 { 33 if (contents.find( "boostinspect:" "noend" ) != string::npos) return; 34 35 // this file deliberately contains errors 36 const char test_file_name[] = "wrong_line_ends_test.cpp"; 37 38 char final_char = contents.begin() == contents.end() ? '\0' 39 : *(boost::prior(contents.end())); 40 41 bool failed = final_char != '\n' && final_char != '\r'; 42 43 if (failed && full_path.leaf() != test_file_name) 44 { 45 ++m_files_with_errors; 46 error( library_name, full_path, string(name()) + ' ' + desc() ); 47 } 48 49 if (!failed && full_path.leaf() == test_file_name) 50 { 51 ++m_files_with_errors; 52 error( library_name, full_path, string(name()) + " should not end with a newline" ); 53 } 54 } 55 } // namespace inspect 56 } // namespace boost 57 58 59