Add #include "fl/stl/noexcept.h" if not present. Returns True if added.
(lines: list[str])
| 208 | |
| 209 | |
| 210 | def ensure_include(lines: list[str]) -> bool: |
| 211 | """Add #include "fl/stl/noexcept.h" if not present. Returns True if added.""" |
| 212 | content = "\n".join(lines) |
| 213 | if NOEXCEPT_INCLUDE in content: |
| 214 | return False |
| 215 | |
| 216 | # Find last #include line |
| 217 | last_idx = -1 |
| 218 | for i, line in enumerate(lines): |
| 219 | if line.strip().startswith("#include"): |
| 220 | last_idx = i |
| 221 | |
| 222 | if last_idx >= 0: |
| 223 | lines.insert(last_idx + 1, NOEXCEPT_INCLUDE) |
| 224 | else: |
| 225 | # After #pragma once |
| 226 | for i, line in enumerate(lines): |
| 227 | if "#pragma once" in line: |
| 228 | lines.insert(i + 1, NOEXCEPT_INCLUDE) |
| 229 | return True |
| 230 | lines.insert(0, NOEXCEPT_INCLUDE) |
| 231 | |
| 232 | return True |
| 233 | |
| 234 | |
| 235 | # ============================================================================ |