Files
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

36 lines
884 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 表达式符号转换器 — 翻译自 CalculatorExpressionTokenizer.java
*
* ASCII (内部) ↔ 显示 (本地化) 符号映射
*/
const TOKEN_MAP: [string, string][] = [
['/', '÷'],
['*', '×'],
['-', '\u2212'], // U+2212 MINUS SIGN
['Infinity', '∞'],
];
/** 将显示字符串转换为 ASCII 内部表示 */
export function normalize(expr: string): string {
let result = expr;
for (const [ascii, display] of TOKEN_MAP) {
result = result.replaceAll(display, ascii);
}
return result;
}
/** 将 ASCII 内部表示转换为显示字符串 */
export function localize(expr: string): string {
let result = expr;
for (const [ascii, display] of TOKEN_MAP) {
result = result.replaceAll(ascii, display);
}
return result;
}
/** 判断字符是否为数字 */
export function isDigit(ch: string): boolean {
return ch >= '0' && ch <= '9';
}