third_party/blink/renderer/bindings/scripts/utilities.py
def format_blink_cpp_source_code(text):
    """Formats C++ source code.

    Supported modifications are:
    - Reduces successive empty lines into a single empty line.
    - Removes empty lines just after an open brace or before closing brace.
      This rule does not apply to namespaces.

    Designed to be used as a filter function for Jinja2.

    Args:
        text: A str of C++ source code.

    Returns:
        A formatted str of the source code.
    """
    re_empty_line = re.compile(r'^\s*$')
    re_first_brace = re.compile(r'(?P<first>[{}])')
    re_last_brace = re.compile(r'.*(?P<last>[{}]).*?$')
    was_open_brace = True  # Trick to remove the empty lines at the beginning.
    was_empty_line = False
    output = []
    for line in text.split('\n'):
        # Skip empty lines.
        if line == '' or re_empty_line.match(line):
            was_empty_line = True
            continue

        # Emit a single empty line if needed.
        if was_empty_line:
            was_empty_line = False
            if '}' in line:
                match = re_first_brace.search(line)
            else:
                match = None

            if was_open_brace:
                # No empty line just after an open brace.
                pass
            elif (match and match.group('first') == '}'
                  and 'namespace' not in line):
                # No empty line just before a closing brace.
                pass
            else:
                # Preserve a single empty line.
                output.append('')

        # Emit the line itself.
        output.append(line)

        # Remember an open brace.
        if '{' in line:
            match = re_last_brace.search(line)
        else:
            match = None
        was_open_brace = (match and match.group('last') == '{'
                          and 'namespace' not in line)

    # Let |'\n'.join| emit the last newline.
    if output:
        output.append('')

    return '\n'.join(output)
Formats C++ source code.

    Supported modifications are:
    - Reduces successive empty lines into a single empty line.
    - Removes empty lines just after an open brace or before closing brace.
      This rule does not apply to namespaces.

    Designed to be used as a filter function for Jinja2.

    Args:
        text: A str of C++ source code.

    Returns:
        A formatted str of the source code.
    
Formats C++ source code.
Supported modifications are:
Reduces successive empty lines into a single empty line.
Removes empty lines just after an open brace or before closing brace.
This rule does not apply to namespaces.

Designed to be used as a filter function for Jinja2.
Formats C ++ source code . Supported modifications are : Reduces successive empty lines into a single empty line . Removes empty lines just after an open brace or before closing brace . This rule does not apply to namespaces . Designed to be used as a filter function for Jinja2 .
def format_blink_cpp_source_code(text):
    re_empty_line = re.compile(r'^\s*$')
    re_first_brace = re.compile(r'(?P<first>[{}])')
    re_last_brace = re.compile(r'.*(?P<last>[{}]).*?$')
    was_open_brace = True  
    was_empty_line = False
    output = []
    for line in text.split('\n'):
        if line == '' or re_empty_line.match(line):
            was_empty_line = True
            continue
        if was_empty_line:
            was_empty_line = False
            if '}' in line:
                match = re_first_brace.search(line)
            else:
                match = None
            if was_open_brace:
                pass
            elif (match and match.group('first') == '}'
                  and 'namespace' not in line):
                pass
            else:
                output.append('')
        output.append(line)
        if '{' in line:
            match = re_last_brace.search(line)
        else:
            match = None
        was_open_brace = (match and match.group('last') == '{'
                          and 'namespace' not in line)
    if output:
        output.append('')
    return '\n'.join(output)
def format_blink_cpp_source_code ( text ) : re_empty_line = re . compile ( r'^\s*$' ) re_first_brace = re . compile ( r'(?P<first>[{}])' ) re_last_brace = re . compile ( r'.*(?P<last>[{}]).*?$' ) was_open_brace = True was_empty_line = False output = [ ] for line in text . split ( '\n' ) : if line == '' or re_empty_line . match ( line ) : was_empty_line = True continue if was_empty_line : was_empty_line = False if '}' in line : match = re_first_brace . search ( line ) else : match = None if was_open_brace : pass elif ( match and match . group ( 'first' ) == '}' and 'namespace' not in line ) : pass else : output . append ( '' ) output . append ( line ) if '{' in line : match = re_last_brace . search ( line ) else : match = None was_open_brace = ( match and match . group ( 'last' ) == '{' and 'namespace' not in line ) if output : output . append ( '' ) return '\n' . join ( output )
Formats C++ source code.
Formats C ++ source code .
"""Formats C++ source code.

    Supported modifications are:
    - Reduces successive empty lines into a single empty line.
    - Removes empty lines just after an open brace or before closing brace.
      This rule does not apply to namespaces.

    Designed to be used as a filter function for Jinja2.

    Args:
        text: A str of C++ source code.

    Returns:
        A formatted str of the source code.
    """ # Trick to remove the empty lines at the beginning. # Skip empty lines. # Emit a single empty line if needed. # No empty line just after an open brace. # No empty line just before a closing brace. # Preserve a single empty line. # Emit the line itself. # Remember an open brace. # Let |'\n'.join| emit the last newline.
A formatted str of the source code.
A formatted str of the source code .
text
A str of C++ source code.
A str of C ++ source code .