diff options
author | kotfu <kotfu@kotfu.net> | 2018-04-30 16:43:30 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-04-30 16:43:30 -0600 |
commit | 32363e20947cfa70239234d6ccc8e39cac643aa7 (patch) | |
tree | 41ec66ba97fd6bdcb001e70aa0133abd6d179999 /cmd2/utils.py | |
parent | b6b4ba212abae5a1394448d0ea5aab34158ef64c (diff) | |
download | cmd2-git-32363e20947cfa70239234d6ccc8e39cac643aa7.tar.gz |
extract strip_quotes() to utils module
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 33215dc0..6abab94c 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -11,3 +11,15 @@ 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 |