Let's try mozilla's fixedCharAt function
This commit is contained in:
parent
69c62365ba
commit
ec78f86ff7
@ -210,6 +210,7 @@ function design4(input) {
|
|||||||
}
|
}
|
||||||
return outputString;
|
return outputString;
|
||||||
}
|
}
|
||||||
|
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||||
var charIterateState;
|
var charIterateState;
|
||||||
function charIterate(input) {
|
function charIterate(input) {
|
||||||
if (charIterateState == undefined) {
|
if (charIterateState == undefined) {
|
||||||
@ -218,6 +219,9 @@ function charIterate(input) {
|
|||||||
} else {
|
} else {
|
||||||
if (charIterateState < (input.length - 1)) {
|
if (charIterateState < (input.length - 1)) {
|
||||||
charIterateState++;
|
charIterateState++;
|
||||||
|
if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) {
|
||||||
|
charIterateState++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
charIterateState = 0;
|
charIterateState = 0;
|
||||||
}
|
}
|
||||||
@ -288,7 +292,7 @@ function design5(input) {
|
|||||||
function fixedCharAt(str, idx) {
|
function fixedCharAt(str, idx) {
|
||||||
str = String(str);
|
str = String(str);
|
||||||
|
|
||||||
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
//const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||||
while (surrogatePairs.exec(str) !== null) {
|
while (surrogatePairs.exec(str) !== null) {
|
||||||
const lastIdx = surrogatePairs.lastIndex;
|
const lastIdx = surrogatePairs.lastIndex;
|
||||||
if (lastIdx - 2 < idx) {
|
if (lastIdx - 2 < idx) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user