INNER CODE UNIT · Python

format_braces

veg/hyphy · Testing/format_braces.py:3

def format_braces(filepath):
    with open(filepath, 'r') as f:
        lines = f.readlines()
        
    out_lines = []
    i = 0
    while i < len(lines):
        line = lines[i]
        stripped = line.strip()
        
        if stripped == "{":
            # If the current line is just "{", we should append it to the previous line
            if out_lines:
                prev_line = out_lines.pop()
                # Remove trailing newline and add " {"
                out_lines.append(prev_line.rstrip() + " {\n")
        elif stripped.startswith("{") and len(stripped) > 1:
            # If the line starts with "{" but has other stuff, e.g. "{ return 1; }"

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…