From 9a1b9d194972fb95eaa74840caad21a5c253d694 Mon Sep 17 00:00:00 2001 From: dludream <127916881+dludream@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:31:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E8=BD=AC=E6=8D=A2=E5=87=BD=E6=95=B0=E5=AF=B9?= =?UTF-8?q?'=E5=8D=81=E3=80=81=E5=8D=81=E4=B8=80'=E7=AD=89=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E7=9A=84=E5=A4=84=E7=90=86=20(#275)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xiaomusic/utils.py b/xiaomusic/utils.py index 92c7304..da9fb75 100644 --- a/xiaomusic/utils.py +++ b/xiaomusic/utils.py @@ -526,6 +526,13 @@ def chinese_to_number(chinese): result = 0 unit = 1 num = 0 + # 处理特殊情况:以"十"开头时,在前面加"一" + if chinese.startswith('十'): + chinese = '一' + chinese + + # 如果只有一个字符且是单位,直接返回其值 + if len(chinese) == 1 and chinese_to_arabic[chinese] >= 10: + return chinese_to_arabic[chinese] for char in reversed(chinese): if char in chinese_to_arabic: val = chinese_to_arabic[char] @@ -536,8 +543,8 @@ def chinese_to_number(chinese): unit *= val else: num += val * unit - result += num - num = 0 + result += num + return result