Detect the indentation size used in a TOON string. Args: toon_string: TOON formatted string Returns: Detected indent size (default 2 if unable to detect)
(toon_string: str)
| 11 | |
| 12 | |
| 13 | def detect_indent(toon_string: str) -> int: |
| 14 | """ |
| 15 | Detect the indentation size used in a TOON string. |
| 16 | |
| 17 | Args: |
| 18 | toon_string: TOON formatted string |
| 19 | |
| 20 | Returns: |
| 21 | Detected indent size (default 2 if unable to detect) |
| 22 | """ |
| 23 | lines = toon_string.split(NEWLINE) |
| 24 | |
| 25 | for line in lines: |
| 26 | if not line or not line[0].isspace(): |
| 27 | continue |
| 28 | |
| 29 | # Count leading spaces |
| 30 | indent = 0 |
| 31 | for char in line: |
| 32 | if char == SPACE: |
| 33 | indent += 1 |
| 34 | elif char == '\t': |
| 35 | # Treat tab as 4 spaces |
| 36 | return 4 |
| 37 | else: |
| 38 | break |
| 39 | |
| 40 | # If we found indentation, return it |
| 41 | if indent > 0: |
| 42 | return indent |
| 43 | |
| 44 | # Default to 2 if no indentation found |
| 45 | return 2 |
| 46 | |
| 47 | |
| 48 | class DecoderOptions: |
no outgoing calls
no test coverage detected
searching dependent graphs…