Tokenize a printf-style format string using regex. Return: A list of string literals and a list of FormatOps.
(format_str: str)
| 68 | |
| 69 | |
| 70 | def tokenizer_printf_style(format_str: str) -> tuple[list[str], list[FormatOp]] | None: |
| 71 | """Tokenize a printf-style format string using regex. |
| 72 | |
| 73 | Return: |
| 74 | A list of string literals and a list of FormatOps. |
| 75 | """ |
| 76 | literals: list[str] = [] |
| 77 | specifiers: list[ConversionSpecifier] = parse_conversion_specifiers(format_str) |
| 78 | format_ops = generate_format_ops(specifiers) |
| 79 | if format_ops is None: |
| 80 | return None |
| 81 | |
| 82 | last_end = 0 |
| 83 | for spec in specifiers: |
| 84 | cur_start = spec.start_pos |
| 85 | literals.append(format_str[last_end:cur_start]) |
| 86 | last_end = cur_start + len(spec.whole_seq) |
| 87 | literals.append(format_str[last_end:]) |
| 88 | |
| 89 | return literals, format_ops |
| 90 | |
| 91 | |
| 92 | # The empty Context as an argument for parse_format_value(). |
no test coverage detected
searching dependent graphs…