MCPcopy Create free account
hub / github.com/FastLED/FastLED / is_bracket_balanced

Function is_bracket_balanced

ci/lint_cpp/check_namespace_includes.py:60–83  ·  view source on GitHub ↗

Check if brackets are balanced in a file (after stripping comments). Args: file_path (Path): Path to the file to check Returns: bool: True if brackets are balanced, False otherwise

(file_path: Path)

Source from the content-addressed store, hash-verified

58
59
60def is_bracket_balanced(file_path: Path) -> bool:
61 """
62 Check if brackets are balanced in a file (after stripping comments).
63
64 Args:
65 file_path (Path): Path to the file to check
66
67 Returns:
68 bool: True if brackets are balanced, False otherwise
69 """
70 try:
71 with open(file_path, "r", encoding="utf-8") as f:
72 content = f.read()
73
74 # Strip comments first
75 content = strip_comments(content)
76
77 # Count brackets
78 open_count = content.count("{")
79 close_count = content.count("}")
80
81 return open_count == close_count
82 except (UnicodeDecodeError, IOError):
83 return True # Assume balanced if we can't read
84
85
86def find_includes_after_namespace_thorough(

Callers 2

check_file_contentMethod · 0.85

Calls 3

strip_commentsFunction · 0.70
readMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected