From 1adcc069df6c14b6594f12b2a5c46e7168da2290 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Sun, 30 Apr 2023 19:30:16 -0500 Subject: [PATCH] Let's try mozilla's fixedCharAt function --- commands/drawDesign.cjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/commands/drawDesign.cjs b/commands/drawDesign.cjs index c41b2de..3ab8608 100644 --- a/commands/drawDesign.cjs +++ b/commands/drawDesign.cjs @@ -213,15 +213,18 @@ function design4(input) { const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; var charIterateState; function charIterate(input) { + let stringLength = (input.length - 1); + for (let i = 0; i < stringLength; ++i) { + if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) { + stringLength--; + } + } if (charIterateState == undefined) { console.log("undefined! setting to zero"); charIterateState = 0; } else { - if (charIterateState < (input.length - 1)) { + if (charIterateState < stringLength) { charIterateState++; - if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) { - //charIterateState++; - } } else { charIterateState = 0; }