Browse Source

perf: enhance characters check

master
Dnomd343 2 years ago
parent
commit
cfa9b65a96
  1. 20
      src/punctuation/character.py

20
src/punctuation/character.py

@ -39,20 +39,34 @@ def toUnicode(character: str) -> int: # get unicode number
def showCharacters(characters: list) -> None: # show character stat
letter = []
chinese = []
punctuation = []
def asciiRange(start: str, end: str) -> list:
return list(range(ord(start), ord(end) + 1))
for c in characters:
if int('4E00', 16) < toUnicode(c) < int('9FA5', 16): # chinese unicode range
if int('4E00', 16) <= toUnicode(c) <= int('9FA5', 16): # chinese unicode range
chinese.append(c)
elif toUnicode(c) in ( # numbers and letters
asciiRange('0', '9') + asciiRange('a', 'z') + asciiRange('A', 'Z')
):
letter.append(c)
else:
punctuation.append(c)
print('\n\033[0;32mPunctuations\033[0;39m\033[0;35m(%d)\033[0;39m\n%s\n' % (
len(punctuation), ' '.join(['`\033[0;33m%s\033[0;39m`' % p for p in punctuation])
len(punctuation), '|'.join(['[\033[0;33m%s\033[0;39m]' % p for p in punctuation])
))
print('\033[0;32mLetters\033[0;39m\033[0;35m(%d)\033[0;39m' % len(letter))
print(' '.join(['\033[0;31m%s\033[0;39m' % c for c in letter]) + '\n')
print('\033[0;32mChinese\033[0;39m\033[0;35m(%d)\033[0;39m' % len(chinese))
for i in range(0, len(chinese)):
print('\033[0;36m%s\033[0;39m%s' % (
chinese[i], '\n' if i % 64 == 63 else ''
chinese[i], '\n' if i % 60 == 59 else ''
), end = '')
print('\n')

Loading…
Cancel
Save