mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
2205d64ea3
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
18 lines
448 B
JavaScript
18 lines
448 B
JavaScript
export function ucs2length(s) {
|
|
let result = 0;
|
|
let length = s.length;
|
|
let index = 0;
|
|
let charCode;
|
|
while (index < length) {
|
|
result++;
|
|
charCode = s.charCodeAt(index++);
|
|
if (charCode >= 0xd800 && charCode <= 0xdbff && index < length) {
|
|
charCode = s.charCodeAt(index);
|
|
if ((charCode & 0xfc00) == 0xdc00) {
|
|
index++;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|