diff options
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 167879aa..a975c6b8 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -5,6 +5,7 @@ import collections from . import constants + def strip_ansi(text: str) -> str: """Strip ANSI escape codes from a string. @@ -14,6 +15,19 @@ def strip_ansi(text: str) -> str: return constants.ANSI_ESCAPE_RE.sub('', text) +def strip_quotes(arg: str) -> str: + """ Strip outer quotes from a string. + + Applies to both single and double quotes. + + :param arg: string to strip outer quotes from + :return: same string with potentially outer quotes stripped + """ + if len(arg) > 1 and arg[0] == arg[-1] and arg[0] in constants.QUOTES: + arg = arg[1:-1] + return arg + + def namedtuple_with_defaults(typename, field_names, default_values=()): """ Convenience function for defining a namedtuple with default values @@ -41,3 +55,4 @@ def namedtuple_with_defaults(typename, field_names, default_values=()): prototype = T(*default_values) T.__new__.__defaults__ = tuple(prototype) return T + |