Skip to content

Commit

Permalink
Merge pull request #460 from ajratnam/main
Browse files Browse the repository at this point in the history
Add and Fix docs for split_unescape
  • Loading branch information
fliiiix authored Oct 12, 2023
2 parents a515e15 + 46580cc commit 7af5ba7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions radish/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,27 @@ def flattened_basedirs(basedirs):

def split_unescape(s, delim, escape="\\", unescape=True):
"""
Split a string based on a delimiter and an escape character.
:param str s: The input string to split and unescape.
:param str delim: The delimiter used for splitting the string.
:param str escape: The escape character used to escape special characters (default is "\\").
:param bool unescape: A flag to control whether to unescape escaped characters (default is True).
:rtype: list
:returns: A list of split and unescaped strings.
Examples:
>>> split_unescape('foo|bar', '|')
['foo', 'bar']
>>> split_unescape(r'foo\|bar', '|')
>>> split_unescape('foo\\|bar', '|')
['foo|bar']
>>> split_unescape(r'foo\\|bar', '|', unescape=True)
[r'foo|', 'bar']
['foo\\', 'bar']
>>> split_unescape(r'foo\\|bar', '|', unescape=False)
[r'foo\\', 'bar']
>>> split_unescape(r'foo\', '|', unescape=True)
[r'foo\']
['foo\\\\', 'bar']
>>> split_unescape('foo\\', '|', unescape=True)
['foo\\']
"""
ret = []
current = []
Expand Down

0 comments on commit 7af5ba7

Please sign in to comment.