inspect/crlf_check.cpp
Daniel James 3105e4629d Merge several documentation fixes. Plus a small inspect fix.
Merged revisions 50798-50799,50837-50839,50847-50848 via svnmerge from 
https://svn.boost.org/svn/boost/trunk

........
  r50798 | danieljames | 2009-01-26 23:14:53 +0000 (Mon, 26 Jan 2009) | 5 lines
  
  Make checking for duplicated names case insensitive.
  
  This avoids generating filenames with names that only differ by case as they
  cause problems on case insensitive file systems.
........
  r50799 | danieljames | 2009-01-26 23:29:52 +0000 (Mon, 26 Jan 2009) | 1 line
  
  Label the line ending inspect errors.
........
  r50837 | danieljames | 2009-01-28 09:14:21 +0000 (Wed, 28 Jan 2009) | 1 line
  
  Add scope exit to the root html file.
........
  r50838 | danieljames | 2009-01-28 09:14:45 +0000 (Wed, 28 Jan 2009) | 1 line
  
  Fix a link in the typeof forwarding html file.
........
  r50839 | danieljames | 2009-01-28 09:14:56 +0000 (Wed, 28 Jan 2009) | 1 line
  
  Fix an incorrectly escaped right arrow.
........
  r50847 | danieljames | 2009-01-28 15:17:34 +0000 (Wed, 28 Jan 2009) | 2 lines
  
  Fix some documentation issues with scope_exit.
........
  r50848 | danieljames | 2009-01-28 15:32:46 +0000 (Wed, 28 Jan 2009) | 1 line
  
  Generate the scope_exit documentation.
........


[SVN r50849]
2009-01-28 15:53:42 +00:00

98 lines
2.7 KiB
C++

// crlf_check implementation ------------------------------------------------//
// Copyright Beman Dawes 2002.
//
// 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)
// Contributed by Joerg Walter
#include "crlf_check.hpp"
namespace boost
{
namespace inspect
{
crlf_check::crlf_check() : m_files_with_errors(0)
{
}
void crlf_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:" "nocrlf" ) != string::npos) return;
// this file deliberately contains errors
const char test_file_name[] = "wrong_line_ends_test.cpp";
bool failed = false;
// The understanding on line endings, as I remember it, was that
// either "\n" or "\r\n" is OK, and they can be mixed, but "\r" alone
// is not acceptable. Mixed line endings are allowed because Boost files
// are commonly edited in both Windows and UNIX environments, and editors
// in those environments generally accept either ending. Even Mac people
// agreed with this policy. --Beman
// Joerg's original implementation is saved below,
// in case we change our minds!
for ( std::string::const_iterator itr ( contents.begin() );
itr != contents.end(); ++itr )
{
if ( *itr == '\r' && ((itr+1) == contents.end() || *(itr+1) != '\n') )
{
failed = true;
break;
}
}
if (failed && full_path.leaf() != test_file_name)
{
++m_files_with_errors;
error( library_name, full_path, name() );
}
if (!failed && full_path.leaf() == test_file_name)
{
++m_files_with_errors;
error( library_name, full_path, string(name()) + " should have cr-only line endings" );
}
/*
size_t cr_count = 0;
size_t lf_count = 0;
size_t crlf_count = 0;
bool had_cr = false;
for ( size_t i = 0; i < contents.length(); ++i )
{
switch ( contents[i] )
{
case '\r':
had_cr = true;
++cr_count;
break;
case '\n':
++lf_count;
if ( had_cr )
++crlf_count;
// fallthrough
default:
had_cr = false;
break;
}
}
if ( cr_count > 0 && lf_count != crlf_count )
{
++m_files_with_errors;
error( library_name, full_path, desc() );
}
*/
}
} // namespace inspect
} // namespace boost