Let's try mozilla's fixedCharAt function
This commit is contained in:
parent
5cf9dab550
commit
1adcc069df
@ -213,15 +213,18 @@ function design4(input) {
|
|||||||
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||||
var charIterateState;
|
var charIterateState;
|
||||||
function charIterate(input) {
|
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) {
|
if (charIterateState == undefined) {
|
||||||
console.log("undefined! setting to zero");
|
console.log("undefined! setting to zero");
|
||||||
charIterateState = 0;
|
charIterateState = 0;
|
||||||
} else {
|
} else {
|
||||||
if (charIterateState < (input.length - 1)) {
|
if (charIterateState < stringLength) {
|
||||||
charIterateState++;
|
charIterateState++;
|
||||||
if (surrogatePairs.exec(input.charCodeAt(charIterateState)) !== null) {
|
|
||||||
//charIterateState++;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
charIterateState = 0;
|
charIterateState = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user