From e0b3279cc17aab1b8e5967fec81a34313d786de8 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Sun, 30 Apr 2023 22:55:00 -0500 Subject: [PATCH] Let's try mozilla's fixedCharAt function --- commands/drawDesign.cjs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/commands/drawDesign.cjs b/commands/drawDesign.cjs index c69d1a3..910f3c9 100644 --- a/commands/drawDesign.cjs +++ b/commands/drawDesign.cjs @@ -217,13 +217,25 @@ function charIterate(input) { let temp = input.split(''); for (let i = 0; i < stringLength; ++i) { let compareString = temp.join(""); - console.log(surrogatePairs.exec(compareString), compareString); - let stringEvalIndex = surrogatePairs.exec(compareString).index; - if (stringEvalIndex != null && stringEvalIndex == i) { - stringLength--; - console.log("Decreasing stringLength variable to", stringLength); + //console.log(surrogatePairs.exec(compareString), compareString); + let stringEval = undefined, stringEvalIndex = undefined; + try { + while ((stringEval = surrogatePairs.exec(compareString)) !== null) { + stringEvalIndex = stringEval.index; + //console.log("emoji is at index", stringEvalIndex); + } + + + } catch (e) { + console.log(e); + console.log("Handling exception..."); } - temp.shift(); + if (stringEvalIndex == i) { + stringLength--; + temp.splice(i, 1); + //console.log("Decreasing stringLength variable to", stringLength); + } + } if (charIterateState == undefined) { console.log("undefined! setting to zero");