Add #include "fl/stl/noexcept.h" if not present. Returns True if added.
(lines: list[str])
| 358 | |
| 359 | |
| 360 | def _ensure_include(lines: list[str]) -> bool: |
| 361 | """Add #include "fl/stl/noexcept.h" if not present. Returns True if added.""" |
| 362 | content = "\n".join(lines) |
| 363 | if _NOEXCEPT_INCLUDE in content: |
| 364 | return False |
| 365 | |
| 366 | last_include = -1 |
| 367 | for i, line in enumerate(lines): |
| 368 | if line.strip().startswith("#include"): |
| 369 | last_include = i |
| 370 | |
| 371 | if last_include >= 0: |
| 372 | lines.insert(last_include + 1, _NOEXCEPT_INCLUDE) |
| 373 | else: |
| 374 | for i, line in enumerate(lines): |
| 375 | if "#pragma once" in line: |
| 376 | lines.insert(i + 1, _NOEXCEPT_INCLUDE) |
| 377 | return True |
| 378 | lines.insert(0, _NOEXCEPT_INCLUDE) |
| 379 | |
| 380 | return True |
| 381 | |
| 382 | |
| 383 | # ============================================================================ |