From 175e8c0a16daf36bd027168328194df974886d41 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 22 Jan 2020 16:31:58 +0000 Subject: change utils.irc.strip_font() to remove tokens, no regex --- src/utils/irc.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/utils') diff --git a/src/utils/irc.py b/src/utils/irc.py index 373f3930..400d5352 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -67,13 +67,6 @@ def bold(s: str) -> str: def underline(s: str) -> str: 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 = [ consts.BOLD, consts.RESET, @@ -183,6 +176,11 @@ def parse_format(s: str) -> str: s += consts.ANSI_RESET 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] class IRCConnectionParameters(object): def __init__(self, id: int, alias: str, hostname: str, port: int, -- cgit v1.3.1-10-gc9f91