Port enhancements from NMA
This commit is contained in:
parent
0a6e2acea5
commit
3257562ff6
58
index.html
58
index.html
@ -223,22 +223,41 @@
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
|
||||
var charIterateState;
|
||||
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
function charIterate(input) {
|
||||
let stringLength = (input.length - 1);
|
||||
let temp = input.split('');
|
||||
for (let i = 0; i < stringLength; ++i) {
|
||||
let compareString = temp.join("");
|
||||
let stringEval = undefined, stringEvalIndex = undefined;
|
||||
while ((stringEval = surrogatePairs.exec(compareString)) !== null) {
|
||||
stringEvalIndex = stringEval.index;
|
||||
console.log("emoji is at index", stringEvalIndex);
|
||||
}
|
||||
if (stringEvalIndex == i) {
|
||||
stringLength--;
|
||||
temp.splice(i, 1);
|
||||
console.log("Decreasing stringLength variable to", stringLength);
|
||||
}
|
||||
}
|
||||
if (charIterateState == undefined) {
|
||||
//console.log("undefined! setting to zero");
|
||||
charIterateState = 0;
|
||||
} else {
|
||||
if (charIterateState < (input.length - 1)) {
|
||||
if (charIterateState < stringLength) {
|
||||
charIterateState++;
|
||||
} else {
|
||||
charIterateState = 0;
|
||||
}
|
||||
}
|
||||
console.log(charIterateState, input.charAt(charIterateState));
|
||||
//console.log(charIterateState, fixedCharAt(input, charIterateState));
|
||||
return charIterateState;
|
||||
}
|
||||
|
||||
function design5(input) {
|
||||
charIterateState = undefined;
|
||||
let outputString = "";
|
||||
let outputLine = "";
|
||||
let radius = (input.length);
|
||||
@ -275,25 +294,54 @@
|
||||
|
||||
if (dist > radius - 1 && dist < radius + 1) { //&& dist > radius - 1
|
||||
lineHasInput = true;
|
||||
outputLine += input.charAt(charIterate(input));
|
||||
outputLine += "" + fixedCharAt(input, charIterate(input)); //zero-width space
|
||||
} else {
|
||||
outputLine += " ";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lineHasInput = true;
|
||||
outputLine += input.charAt(charIterate(input)) + space + input + space + spaceOffset + input.charAt(charIterate(input));
|
||||
outputLine += fixedCharAt(input, charIterate(input)) + space + input + space + spaceOffset + fixedCharAt(input, charIterate(input));
|
||||
}
|
||||
|
||||
//console.log(i, j, outputLine);
|
||||
if (lineHasInput) {
|
||||
console.log("outputLine", outputLine);
|
||||
outputString += outputLine + "<br>";
|
||||
}
|
||||
outputLine = "";
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
|
||||
// Code from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
|
||||
|
||||
function fixedCharAt(str, idx) {
|
||||
str = String(str);
|
||||
|
||||
//const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
while (surrogatePairs.exec(str) !== null) {
|
||||
const lastIdx = surrogatePairs.lastIndex;
|
||||
if (lastIdx - 2 < idx) {
|
||||
idx++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx >= str.length || idx < 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let ret = str.charAt(idx);
|
||||
if (
|
||||
/[\uD800-\uDBFF]/.test(ret) &&
|
||||
/[\uDC00-\uDFFF]/.test(str.charAt(idx + 1))
|
||||
) {
|
||||
// Go one further, since one of the "characters" is part of a surrogate pair
|
||||
ret += str.charAt(idx + 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
</script>
|
||||
<p id="jsOutput"></p>
|
||||
<img id=riitag src="https://tag.rc24.xyz/294976590658666497/tag.max.png" alt="My RiiTag" width=1024>
|
||||
|
Loading…
x
Reference in New Issue
Block a user