parameters: (lines)
return_statement: return retval[:-1]
docstring: Normalize' namespace lines in a list of output lines and return new list.
  
    When suggesting new forward-declares to insert, iwyu uses the following
    format, putting each class on its own line with all namespaces:
       namespace foo { namespace bar { class A; } }
       namespace foo { namespace bar { class B; } }
       namespace foo { namespace bang { class C; } }
    We convert this to 'normalized' form, which puts namespaces on their
    own line and collects classes together:
       namespace foo {
       namespace bar {
       class A;
       class B;
       }  // namespace bar
       namespace bang {
       class C;
       }  // namespace bang
       }  // namespace foo
  
    Non-namespace lines are left alone.  Only adjacent namespace lines
    from the input are merged.
  
    Arguments:
      lines: a list of output-lines -- that is, lines that are ready to
         be emitted as-is to the output file.
  
    Returns:
      A new version of lines, with namespace lines normalized as above.
docstring_summary: Normalize' namespace lines in a list of output lines and return new list.
docstring_tokens: Normalize namespace lines in a list of output lines and return new list .
function: def _NormalizeNamespaceForwardDeclareLines(lines):
    """'Normalize' namespace lines in a list of output lines and return new list.
  
    When suggesting new forward-declares to insert, iwyu uses the following
    format, putting each class on its own line with all namespaces:
       namespace foo { namespace bar { class A; } }
       namespace foo { namespace bar { class B; } }
       namespace foo { namespace bang { class C; } }
    We convert this to 'normalized' form, which puts namespaces on their
    own line and collects classes together:
       namespace foo {
       namespace bar {
       class A;
       class B;
       }  // namespace bar
       namespace bang {
       class C;
       }  // namespace bang
       }  // namespace foo
  
    Non-namespace lines are left alone.  Only adjacent namespace lines
    from the input are merged.
  
    Arguments:
      lines: a list of output-lines -- that is, lines that are ready to
         be emitted as-is to the output file.
  
    Returns:
      A new version of lines, with namespace lines normalized as above.
    """
    # iwyu input is very regular, which is nice.
    iwyu_namespace_re = re.compile(r'namespace ([^{]*) { ')
    iwyu_classname_re = re.compile(r'{ ([^{}]*) }')
  
    retval = []
    current_namespaces = []
    # We append a blank line so the final namespace-closing happens "organically".
    for line in lines + ['']:
      namespaces_in_line = iwyu_namespace_re.findall(line)
      differ_pos = _CommonPrefixLength(namespaces_in_line, current_namespaces)
      namespaces_to_close = reversed(current_namespaces[differ_pos:])
      namespaces_to_open = namespaces_in_line[differ_pos:]
      retval.extend('}  // namespace %s' % ns for ns in namespaces_to_close)
      retval.extend('namespace %s {' % ns for ns in namespaces_to_open)
      current_namespaces = namespaces_in_line
      # Now add the current line.  If we were a namespace line, it's the
      # 'class' part of the line (everything but the 'namespace {'s).
      if namespaces_in_line:
        m = iwyu_classname_re.search(line)
        if not m:
          raise FixIncludesError('Malformed namespace line from iwyu: %s', line)
        retval.append(m.group(1))
      else:
        retval.append(line)
  
    assert retval and retval[-1] == '', 'What happened to our sentinel line?'
    return retval[:-1]
function_tokens: def _NormalizeNamespaceForwardDeclareLines ( lines ) : # iwyu input is very regular, which is nice. iwyu_namespace_re = re . compile ( r'namespace ([^{]*) { ' ) iwyu_classname_re = re . compile ( r'{ ([^{}]*) }' ) retval = [ ] current_namespaces = [ ] # We append a blank line so the final namespace-closing happens "organically". for line in lines + [ '' ] : namespaces_in_line = iwyu_namespace_re . findall ( line ) differ_pos = _CommonPrefixLength ( namespaces_in_line , current_namespaces ) namespaces_to_close = reversed ( current_namespaces [ differ_pos : ] ) namespaces_to_open = namespaces_in_line [ differ_pos : ] retval . extend ( '}  // namespace %s' % ns for ns in namespaces_to_close ) retval . extend ( 'namespace %s {' % ns for ns in namespaces_to_open ) current_namespaces = namespaces_in_line # Now add the current line.  If we were a namespace line, it's the # 'class' part of the line (everything but the 'namespace {'s). if namespaces_in_line : m = iwyu_classname_re . search ( line ) if not m : raise FixIncludesError ( 'Malformed namespace line from iwyu: %s' , line ) retval . append ( m . group ( 1 ) ) else : retval . append ( line ) assert retval and retval [ - 1 ] == '' , 'What happened to our sentinel line?' return retval [ : - 1 ]