change utils.irc.strip_font() to remove tokens, no regex

This commit is contained in:
jesopo 2020-01-22 16:31:58 +00:00
parent 363fdf01b0
commit 175e8c0a16

View file

@ -67,13 +67,6 @@ def bold(s: str) -> str:
def underline(s: str) -> str: def underline(s: str) -> str:
return f"{consts.UNDERLINE}{s}{consts.UNDERLINE}" return f"{consts.UNDERLINE}{s}{consts.UNDERLINE}"
def strip_font(s: str) -> str:
s = s.replace(consts.BOLD, "")
s = s.replace(consts.ITALIC, "")
s = REGEX_COLOR.sub("", s)
s = s.replace(consts.COLOR, "")
return s
FORMAT_TOKENS = [ FORMAT_TOKENS = [
consts.BOLD, consts.BOLD,
consts.RESET, consts.RESET,
@ -183,6 +176,11 @@ def parse_format(s: str) -> str:
s += consts.ANSI_RESET s += consts.ANSI_RESET
return s return s
def strip_font(s: str) -> str:
for token in _format_tokens(s):
s = s.replace(token, "", 1)
return s
OPT_STR = typing.Optional[str] OPT_STR = typing.Optional[str]
class IRCConnectionParameters(object): class IRCConnectionParameters(object):
def __init__(self, id: int, alias: str, hostname: str, port: int, def __init__(self, id: int, alias: str, hostname: str, port: int,