diff options
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 33215dc0..9705e4f7 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -4,6 +4,7 @@ from . import constants + def strip_ansi(text: str) -> str: """Strip ANSI escape codes from a string. @@ -11,3 +12,16 @@ def strip_ansi(text: str) -> str: :return: the same string with any ANSI escape codes removed """ 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 |