修正全角数字存入数据库失败的问题
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import unicodedata
|
||||
|
||||
|
||||
def blank(string):
|
||||
"""
|
||||
判断字符串是否为空或者纯空格
|
||||
@@ -5,3 +8,23 @@ def blank(string):
|
||||
:return: 字符串是否为空或者纯空格
|
||||
"""
|
||||
return not string or string.isspace()
|
||||
|
||||
|
||||
def full_to_half(string):
|
||||
"""
|
||||
全角转半角
|
||||
:param string: 字符串
|
||||
:return: 半角字符串
|
||||
"""
|
||||
if not isinstance(string, str):
|
||||
raise TypeError("全角转半角的输入必须是字符串类型")
|
||||
|
||||
if not string:
|
||||
return string
|
||||
|
||||
half_string = ''.join([
|
||||
unicodedata.normalize('NFKC', char) if unicodedata.east_asian_width(char) in ['F', 'W'] else char
|
||||
for char in string
|
||||
])
|
||||
|
||||
return half_string
|
||||
|
||||
Reference in New Issue
Block a user