* Removes spans from a string, returning the string with those character * ranges removed.
(command: string, spans: Array<[number, number]>)
| 176 | * ranges removed. |
| 177 | */ |
| 178 | function removeSpans(command: string, spans: Array<[number, number]>): string { |
| 179 | if (spans.length === 0) return command |
| 180 | |
| 181 | // Drop inner spans that are fully contained in an outer one, then sort by |
| 182 | // start index descending so we can splice without offset shifts. |
| 183 | const sorted = dropContainedSpans(spans).sort((a, b) => b[0] - a[0]) |
| 184 | let result = command |
| 185 | for (const [start, end] of sorted) { |
| 186 | result = result.slice(0, start) + result.slice(end) |
| 187 | } |
| 188 | return result |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Replaces spans with just the quote delimiters (preserving ' and " characters). |
no test coverage detected