parameters: (filename, clean_lines, linenum, file_extension, nesting_state,
                 error)
docstring: Checks rules from the 'C++ style rules' section of cppguide.html.
  
    Most of these rules are hard to test (naming, comment style), but we
    do what we can.  In particular we check for 2-space indents, line lengths,
    tab usage, spaces inside code, etc.
  
    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      file_extension: The extension (without the dot) of the filename.
      nesting_state: A _NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.
docstring_summary: Checks rules from the 'C++ style rules' section of cppguide.html.
docstring_tokens: Checks rules from the C ++ style rules section of cppguide . html .
function: def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
                 error):
    """Checks rules from the 'C++ style rules' section of cppguide.html.
  
    Most of these rules are hard to test (naming, comment style), but we
    do what we can.  In particular we check for 2-space indents, line lengths,
    tab usage, spaces inside code, etc.
  
    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      file_extension: The extension (without the dot) of the filename.
      nesting_state: A _NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.
    """
  
    # Don't use "elided" lines here, otherwise we can't check commented lines.
    # Don't want to use "raw" either, because we don't want to check inside C++11
    # raw strings,
    raw_lines = clean_lines.lines_without_raw_strings
    line = raw_lines[linenum]
  
    if line.find('\t') != -1:
      error(filename, linenum, 'whitespace/tab', 1,
            'Tab found; better to use spaces')
  
    # One or three blank spaces at the beginning of the line is weird; it's
    # hard to reconcile that with 2-space indents.
    # NOTE: here are the conditions rob pike used for his tests.  Mine aren't
    # as sophisticated, but it may be worth becoming so:  RLENGTH==initial_spaces
    # if(RLENGTH > 20) complain = 0;
    # if(match($0, " +(error|private|public|protected):")) complain = 0;
    # if(match(prev, "&& *$")) complain = 0;
    # if(match(prev, "\\|\\| *$")) complain = 0;
    # if(match(prev, "[\",=><] *$")) complain = 0;
    # if(match($0, " <<")) complain = 0;
    # if(match(prev, " +for \\(")) complain = 0;
    # if(prevodd && match(prevprev, " +for \\(")) complain = 0;
    initial_spaces = 0
    cleansed_line = clean_lines.elided[linenum]
    while initial_spaces < len(line) and line[initial_spaces] == ' ':
      initial_spaces += 1
    if line and line[-1].isspace():
      error(filename, linenum, 'whitespace/end_of_line', 4,
            'Line ends in whitespace.  Consider deleting these extra spaces.')
    # There are certain situations we allow one space, notably for section labels
    elif ((initial_spaces == 1 or initial_spaces == 3) and
          not Match(r'\s*\w+\s*:\s*$', cleansed_line)):
      error(filename, linenum, 'whitespace/indent', 3,
            'Weird number of spaces at line-start.  '
            'Are you using a 2-space indent?')
  
    # Check if the line is a header guard.
    is_header_guard = False
    if file_extension == 'h':
      cppvar = GetHeaderGuardCPPVariable(filename)
      if (line.startswith('#ifndef %s' % cppvar) or
          line.startswith('#define %s' % cppvar) or
          line.startswith('#endif  // %s' % cppvar)):
        is_header_guard = True
    # #include lines and header guards can be long, since there's no clean way to
    # split them.
    #
    # URLs can be long too.  It's possible to split these, but it makes them
    # harder to cut&paste.
    #
    # The "$Id:...$" comment may also get very long without it being the
    # developers fault.
    if (not line.startswith('#include') and not is_header_guard and
        not Match(r'^\s*//.*http(s?)://\S*$', line) and
        not Match(r'^// \$Id:.*#[0-9]+ \$$', line)):
      line_width = GetLineWidth(line)
      extended_length = int((_line_length * 1.25))
      if line_width > extended_length:
        error(filename, linenum, 'whitespace/line_length', 4,
              'Lines should very rarely be longer than %i characters' %
              extended_length)
      elif line_width > _line_length:
        error(filename, linenum, 'whitespace/line_length', 2,
              'Lines should be <= %i characters long' % _line_length)
  
    if (cleansed_line.count(';') > 1 and
        # for loops are allowed two ;'s (and may run over two lines).
        cleansed_line.find('for') == -1 and
        (GetPreviousNonBlankLine(clean_lines, linenum)[0].find('for') == -1 or
         GetPreviousNonBlankLine(clean_lines, linenum)[0].find(';') != -1) and
        # It's ok to have many commands in a switch case that fits in 1 line
        not ((cleansed_line.find('case ') != -1 or
              cleansed_line.find('default:') != -1) and
             cleansed_line.find('break;') != -1)):
      error(filename, linenum, 'whitespace/newline', 0,
            'More than one command on the same line')
  
    # Some more style checks
    CheckBraces(filename, clean_lines, linenum, error)
    CheckEmptyBlockBody(filename, clean_lines, linenum, error)
    CheckAccess(filename, clean_lines, linenum, nesting_state, error)
    CheckSpacing(filename, clean_lines, linenum, nesting_state, error)
    CheckCheck(filename, clean_lines, linenum, error)
    CheckAltTokens(filename, clean_lines, linenum, error)
    classinfo = nesting_state.InnermostClass()
    if classinfo:
      CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
function_tokens: def CheckStyle ( filename , clean_lines , linenum , file_extension , nesting_state , error ) : # Don't use "elided" lines here, otherwise we can't check commented lines. # Don't want to use "raw" either, because we don't want to check inside C++11 # raw strings, raw_lines = clean_lines . lines_without_raw_strings line = raw_lines [ linenum ] if line . find ( '\t' ) != - 1 : error ( filename , linenum , 'whitespace/tab' , 1 , 'Tab found; better to use spaces' ) # One or three blank spaces at the beginning of the line is weird; it's # hard to reconcile that with 2-space indents. # NOTE: here are the conditions rob pike used for his tests.  Mine aren't # as sophisticated, but it may be worth becoming so:  RLENGTH==initial_spaces # if(RLENGTH > 20) complain = 0; # if(match($0, " +(error|private|public|protected):")) complain = 0; # if(match(prev, "&& *$")) complain = 0; # if(match(prev, "\\|\\| *$")) complain = 0; # if(match(prev, "[\",=><] *$")) complain = 0; # if(match($0, " <<")) complain = 0; # if(match(prev, " +for \\(")) complain = 0; # if(prevodd && match(prevprev, " +for \\(")) complain = 0; initial_spaces = 0 cleansed_line = clean_lines . elided [ linenum ] while initial_spaces < len ( line ) and line [ initial_spaces ] == ' ' : initial_spaces += 1 if line and line [ - 1 ] . isspace ( ) : error ( filename , linenum , 'whitespace/end_of_line' , 4 , 'Line ends in whitespace.  Consider deleting these extra spaces.' ) # There are certain situations we allow one space, notably for section labels elif ( ( initial_spaces == 1 or initial_spaces == 3 ) and not Match ( r'\s*\w+\s*:\s*$' , cleansed_line ) ) : error ( filename , linenum , 'whitespace/indent' , 3 , 'Weird number of spaces at line-start.  ' 'Are you using a 2-space indent?' ) # Check if the line is a header guard. is_header_guard = False if file_extension == 'h' : cppvar = GetHeaderGuardCPPVariable ( filename ) if ( line . startswith ( '#ifndef %s' % cppvar ) or line . startswith ( '#define %s' % cppvar ) or line . startswith ( '#endif  // %s' % cppvar ) ) : is_header_guard = True # #include lines and header guards can be long, since there's no clean way to # split them. # # URLs can be long too.  It's possible to split these, but it makes them # harder to cut&paste. # # The "$Id:...$" comment may also get very long without it being the # developers fault. if ( not line . startswith ( '#include' ) and not is_header_guard and not Match ( r'^\s*//.*http(s?)://\S*$' , line ) and not Match ( r'^// \$Id:.*#[0-9]+ \$$' , line ) ) : line_width = GetLineWidth ( line ) extended_length = int ( ( _line_length * 1.25 ) ) if line_width > extended_length : error ( filename , linenum , 'whitespace/line_length' , 4 , 'Lines should very rarely be longer than %i characters' % extended_length ) elif line_width > _line_length : error ( filename , linenum , 'whitespace/line_length' , 2 , 'Lines should be <= %i characters long' % _line_length ) if ( cleansed_line . count ( ';' ) > 1 and # for loops are allowed two ;'s (and may run over two lines). cleansed_line . find ( 'for' ) == - 1 and ( GetPreviousNonBlankLine ( clean_lines , linenum ) [ 0 ] . find ( 'for' ) == - 1 or GetPreviousNonBlankLine ( clean_lines , linenum ) [ 0 ] . find ( ';' ) != - 1 ) and # It's ok to have many commands in a switch case that fits in 1 line not ( ( cleansed_line . find ( 'case ' ) != - 1 or cleansed_line . find ( 'default:' ) != - 1 ) and cleansed_line . find ( 'break;' ) != - 1 ) ) : error ( filename , linenum , 'whitespace/newline' , 0 , 'More than one command on the same line' ) # Some more style checks CheckBraces ( filename , clean_lines , linenum , error ) CheckEmptyBlockBody ( filename , clean_lines , linenum , error ) CheckAccess ( filename , clean_lines , linenum , nesting_state , error ) CheckSpacing ( filename , clean_lines , linenum , nesting_state , error ) CheckCheck ( filename , clean_lines , linenum , error ) CheckAltTokens ( filename , clean_lines , linenum , error ) classinfo = nesting_state . InnermostClass ( ) if classinfo : CheckSectionSpacing ( filename , clean_lines , classinfo , linenum , error )