Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
added custom _string_width testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rockygo2 committed Jun 14, 2024
1 parent 1f14859 commit 2a0411b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import typing
import warnings
import logging
from cov import test, mark

import yarl

Expand Down Expand Up @@ -821,14 +822,19 @@ def has(self, element: int) -> bool:
return i != len(self) and self[i] == element


@test(4)
def _string_width(string: str) -> int:
"""Returns string's width."""
if string.isascii():
mark(1)
return len(string)

mark(0)
UNICODE_WIDE_CHAR_TYPE = 'WFA'
func = unicodedata.east_asian_width
return sum(2 if func(char) in UNICODE_WIDE_CHAR_TYPE else 1 for char in string)
return sum(
2 if (mark(2, "_string_width"), func(char))[1] in UNICODE_WIDE_CHAR_TYPE else (1, mark(2, "_string_width"))[0]
for char in string
)


class ResolvedInvite(NamedTuple):
Expand Down

0 comments on commit 2a0411b

Please sign in to comment.