fix(sonar): stop reassigning loop counter in quote splitter (javascript:S2310)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8d61f22ba4
commit
bf4a71a61a
@ -13,12 +13,14 @@ function _abImplausibleDialoguePiece(text) {
|
||||
|
||||
function audiobookSplitByQuotes(text) {
|
||||
const spans = [];
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let next = 0;
|
||||
while (next < text.length) {
|
||||
const i = next++;
|
||||
const open = text[i], close = AB_QUOTE_PAIRS[open];
|
||||
if (!close) continue;
|
||||
const minStart = spans.length ? spans[spans.length - 1].end : 0;
|
||||
const orphan = _abOrphanClosingQuoteSpan(text, i, minStart);
|
||||
if (orphan) { spans.push(orphan); i = orphan.end - 1; continue; }
|
||||
if (orphan) { spans.push(orphan); next = orphan.end; continue; }
|
||||
if ((open === '«' || open === '»') && i > 0 && !/[\s([{—–-]/.test(text[i - 1])) continue;
|
||||
const raw = text.slice(i + 1);
|
||||
const closeIdx = raw.indexOf(close);
|
||||
@ -27,7 +29,7 @@ function audiobookSplitByQuotes(text) {
|
||||
if (!quote) continue;
|
||||
const consumedClose = closeIdx >= 0 && endInRaw === closeIdx;
|
||||
spans.push({ start: i, end: i + 1 + endInRaw + (consumedClose ? 1 : 0), quote });
|
||||
i = spans[spans.length - 1].end - 1;
|
||||
next = spans[spans.length - 1].end;
|
||||
}
|
||||
if (!spans.length) return [{ speaker: 'Narrator', type: 'narration', text, emotion: '' }];
|
||||
const out = []; let last = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user