Function
findNthMatchIndex
(fullText: string, matchText: string, occurrenceIndex: number)
Source from the content-addressed store, hash-verified
| 166 | } |
| 167 | |
| 168 | function findNthMatchIndex(fullText: string, matchText: string, occurrenceIndex: number): number { |
| 169 | let currentIndex = 0 |
| 170 | let searchStartIndex = 0 |
| 171 | |
| 172 | while (true) { |
| 173 | const idx = fullText.indexOf(matchText, searchStartIndex) |
| 174 | if (idx === -1) return -1 |
| 175 | |
| 176 | if (currentIndex === occurrenceIndex) { |
| 177 | return idx |
| 178 | } |
| 179 | |
| 180 | currentIndex++ |
| 181 | searchStartIndex = idx + 1 |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * 根据拼接文本的偏移量创建 Range |
Tested by
no test coverage detected