Add #include "fl/stl/noexcept.h" if not already present. Returns True if added.
(lines: list[str])
| 225 | |
| 226 | |
| 227 | def _ensure_include(lines: list[str]) -> bool: |
| 228 | """Add #include "fl/stl/noexcept.h" if not already present. |
| 229 | |
| 230 | Returns True if added. |
| 231 | """ |
| 232 | content = "\n".join(lines) |
| 233 | if _NOEXCEPT_INCLUDE in content: |
| 234 | return False |
| 235 | |
| 236 | # Insert after the last existing #include |
| 237 | last_idx = -1 |
| 238 | for i, line in enumerate(lines): |
| 239 | if line.strip().startswith("#include"): |
| 240 | last_idx = i |
| 241 | |
| 242 | if last_idx >= 0: |
| 243 | lines.insert(last_idx + 1, _NOEXCEPT_INCLUDE) |
| 244 | else: |
| 245 | # Fallback: after #pragma once |
| 246 | for i, line in enumerate(lines): |
| 247 | if "#pragma once" in line: |
| 248 | lines.insert(i + 1, _NOEXCEPT_INCLUDE) |
| 249 | return True |
| 250 | lines.insert(0, _NOEXCEPT_INCLUDE) |
| 251 | |
| 252 | return True |
| 253 | |
| 254 | |
| 255 | # ============================================================================ |