Search for text (with '...' wildcards) across boltsections. Returns (section_idx, start, end) of the match, or (-1, 0, 0) on failure. When a '...' part is not found in the current section we try subsequent sections, so quotes can explicitly span a section header using '*...'. For a
(
text: str, boltsections: List[str]
)
| 157 | |
| 158 | |
| 159 | def find_quote( |
| 160 | text: str, boltsections: List[str] |
| 161 | ) -> Tuple[int, int, int]: |
| 162 | """Search for text (with '...' wildcards) across boltsections. |
| 163 | |
| 164 | Returns (section_idx, start, end) of the match, or (-1, 0, 0) on failure. |
| 165 | When a '...' part is not found in the current section we try subsequent |
| 166 | sections, so quotes can explicitly span a section header using '*...'. |
| 167 | For a cross-section match the start is credited as 0 in the final section. |
| 168 | """ |
| 169 | textparts = text.split("...") |
| 170 | for start_si, start_b in enumerate(boltsections): |
| 171 | cur_si = start_si |
| 172 | cur_section = start_b |
| 173 | off = 0 |
| 174 | match_start = -1 |
| 175 | success = True |
| 176 | for i, part in enumerate(textparts): |
| 177 | new_off = cur_section.find(part, off) |
| 178 | if new_off == -1: |
| 179 | # Try subsequent sections; strip leading whitespace since we're |
| 180 | # starting fresh at position 0 after a section boundary. |
| 181 | found = False |
| 182 | search_part = part.lstrip() |
| 183 | for next_si in range(cur_si + 1, len(boltsections)): |
| 184 | new_off = boltsections[next_si].find(search_part, 0) |
| 185 | if new_off != -1: |
| 186 | cur_si = next_si |
| 187 | cur_section = boltsections[next_si] |
| 188 | # Cross-section: credit coverage from start of this section. |
| 189 | match_start = 0 |
| 190 | off = new_off + len(search_part) |
| 191 | found = True |
| 192 | break |
| 193 | if not found: |
| 194 | success = False |
| 195 | break |
| 196 | else: |
| 197 | if i == 0 and match_start < 0: |
| 198 | match_start = new_off |
| 199 | off = new_off + len(part) |
| 200 | if success: |
| 201 | return cur_si, (match_start if match_start >= 0 else 0), off |
| 202 | return -1, 0, 0 |
| 203 | |
| 204 | |
| 205 | def find_quote_immediate( |