Boost logo

Boost-Commit :

From: marshall_at_[hidden]
Date: 2008-07-02 00:49:09


Author: marshall
Date: 2008-07-02 00:49:09 EDT (Wed, 02 Jul 2008)
New Revision: 46981
URL: http://svn.boost.org/trac/boost/changeset/46981

Log:
Better reporting
Text files modified:
   trunk/tools/inspect/ascii_check.cpp | 43 +++++++++++++++++++++++++++++++++++----
   1 files changed, 38 insertions(+), 5 deletions(-)

Modified: trunk/tools/inspect/ascii_check.cpp
==============================================================================
--- trunk/tools/inspect/ascii_check.cpp (original)
+++ trunk/tools/inspect/ascii_check.cpp 2008-07-02 00:49:09 EDT (Wed, 02 Jul 2008)
@@ -16,8 +16,8 @@
   namespace inspect
   {
 
- static const string gPunct ( "$_{}[]#()<>%:;.?*+-/^&|~!=,\\\"'@^`" );
-
+ static const string gPunct ( "$_{}[]#()<>%:;.?*+-/ˆ&|~!=,\\\"'@^`" );
+
    // Legal characters for a source file are defined in section 2.2 of the standard
    // I have added '@', '^', and '`' to the "legal" chars because they are commonly
    // used in comments, and they are strictly ASCII.
@@ -37,6 +37,38 @@
       }
    };
 
+ struct is_CRLF : public std::unary_function<char, bool> {
+ public:
+ is_CRLF () {}
+ ~is_CRLF () {}
+ bool operator () ( char c ) const
+ {
+ return c == '\015' || c == '\012';
+ }
+ };
+
+ const char *kCRLF = "\012\015";
+
+// Given a position in the file, extract and return the line
+ std::string find_line ( const std::string &contents, std::string::const_iterator iter_pos )
+ {
+ std::size_t pos = iter_pos - contents.begin ();
+
+ // Search backwards for a CR or LR
+ std::size_t start_pos = contents.find_last_of ( kCRLF, pos );
+ std::string::const_iterator line_start = contents.begin () + ( start_pos == std::string::npos ? 0 : start_pos + 1 );
+
+
+ // Search forwards for a CR or LF
+ std::size_t end_pos = contents.find_first_of ( kCRLF, pos + 1 );
+ std::string::const_iterator line_end;
+ if ( end_pos == std::string::npos )
+ line_end = contents.end ();
+ else
+ line_end = contents.begin () + end_pos - 1;
+
+ return std::string ( line_start, line_end );
+ }
 
    ascii_check::ascii_check() : m_files_with_errors(0)
    {
@@ -55,11 +87,12 @@
       const string & contents ) // contents of file to be inspected
     {
       if (contents.find( "boostinspect:" "noascii" ) != string::npos) return;
-
- if ( std::find_if ( contents.begin (), contents.end (), non_ascii ()) != contents.end ())
+ string::const_iterator bad_char = std::find_if ( contents.begin (), contents.end (), non_ascii ());
+ if ( bad_char != contents.end ())
       {
         ++m_files_with_errors;
- error( library_name, full_path, name() );
+ string the_line = find_line ( contents, bad_char );
+ error( library_name, full_path, string ( name()) + " non-ASCII: " + the_line );
       }
     }
   } // namespace inspect


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk