You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
259 B
13 lines
259 B
1 month ago
|
export function getStrBytesCount(str) {
|
||
|
let bytesCount = 0;
|
||
|
for (let i = 0; i < str.length; i++) {
|
||
|
const c = str.charAt(i);
|
||
|
if (/^[\u00-\uff]$/.test(c)) {
|
||
|
bytesCount += 1;
|
||
|
} else {
|
||
|
bytesCount += 2;
|
||
|
}
|
||
|
}
|
||
|
return bytesCount;
|
||
|
}
|