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;
|
||||
}
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user