From ec78f86ff71663b90dffc1bccd283ac200c5dcd6 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Sun, 30 Apr 2023 18:51:08 -0500 Subject: [PATCH] Let's try mozilla's fixedCharAt function --- commands/drawDesign.cjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commands/drawDesign.cjs b/commands/drawDesign.cjs index 4909454..648aa70 100644 --- a/commands/drawDesign.cjs +++ b/commands/drawDesign.cjs @@ -210,6 +210,7 @@ function design4(input) { } return outputString; } +const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; var charIterateState; function charIterate(input) { if (charIterateState == undefined) { @@ -218,6 +219,9 @@ function charIterate(input) { } else { if (charIterateState < (input.length - 1)) { charIterateState++; + if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) { + charIterateState++; + } } else { charIterateState = 0; } @@ -288,7 +292,7 @@ function design5(input) { function fixedCharAt(str, idx) { str = String(str); - const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; + //const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; while (surrogatePairs.exec(str) !== null) { const lastIdx = surrogatePairs.lastIndex; if (lastIdx - 2 < idx) {