fix: 长度计算

This commit is contained in:
AncTe committed 2024-04-23 22:31:08 +08:00
1 parent a735676535
commit 32aaf98fa6
3 files changed
+26 -1

No files matched your search

+16
View File
@@ -511,3 +511,19 @@ export function getIconHeight(icon: AllIds | 'hero') {
}
return core.getBlockInfo(icon)?.height ?? 32;
}
const ascii = 16 ** 2;
const other = 16 ** 4;
const emoji = 16 ** 5;
export function calStringSize(str: string) {
let size = 0;
for (const char of str) {
const num = char.charCodeAt(0);
if (num < ascii) size += 1;
else if (num < other) size += 2;
else if (num < emoji) size += 2.5;
}
return size;
}