Debian Codegraph @

kwsCheckBadCharacters.cxx

raw
1 /*=========================================================================
2
3 Program: KWStyle - Kitware Style Checker
4 Module: kwsCheckBadCharacters.cxx
5
6 Copyright (c) Kitware, Inc. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
12
13 =========================================================================*/
14 #include "kwsParser.h"
15
16 #include "kwsPushBoostWarnings.h"
17 #include <boost/xpressive/xpressive.hpp>
18 #include "kwsPopBoostWarnings.h"
19
20 using namespace boost::xpressive;
21
22 namespace kws {
23
24 /** Check if the current file has bad characters */
25 bool Parser::CheckBadCharacters(bool checkComments)
26 {
27 m_TestsDone[BADCHARACTERS] = true;
28 m_TestsDescription[BADCHARACTERS] = "Checking for bad characters";
29
30 std::string buffer = m_BufferNoComment;
31 if(checkComments)
32 {
33 buffer = m_Buffer;
34 }
35
36 bool hasError = false;
37
38 // space characters along with printable characters (space through
39 // ~) are fine; others are "bad"
40 sregex lineWithBadCharRegex =
41 sregex::compile(R"(^[^\r\n]*?([^\s[:print:]])[^\r\n]*$)");
42 sregex_iterator currentBadCharIterator(buffer.begin(), buffer.end(), lineWithBadCharRegex);
43 sregex_iterator end;
44
45 for (; currentBadCharIterator != end; ++currentBadCharIterator)
46 {
47 Error error;
48 smatch const &currentMatch = *currentBadCharIterator;
49 error.line = this->GetLineNumber(currentMatch.position(1), !checkComments);
50 error.line2 = error.line;
51 error.number = BADCHARACTERS;
52 error.description = "Bad character";
53 m_ErrorList.push_back(error);
54 hasError = true;
55 }
56
57 return !hasError;
58 }
59
60 } // end namespace kws