Skip to content

Commit

Permalink
Use built-in isascii instead of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Aug 17, 2022
1 parent d78be1f commit f52a023
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,10 @@ def has(self, element: int) -> bool:
return i != len(self) and self[i] == element


_IS_ASCII = re.compile(r'^[\x00-\x7f]+$')


def _string_width(string: str, *, _IS_ASCII=_IS_ASCII) -> int:
def _string_width(string: str) -> int:
"""Returns string's width."""
match = _IS_ASCII.match(string)
if match:
return match.endpos
if string.isascii():
return len(string)

UNICODE_WIDE_CHAR_TYPE = 'WFA'
func = unicodedata.east_asian_width
Expand Down

0 comments on commit f52a023

Please sign in to comment.