mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-03 18:24:30 +08:00
fix: 长度计算
This commit is contained in:
1 parent
a735676535
commit
32aaf98fa6
3 files changed
+26
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user