Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added django.utils.text.smart_split. Thanks, ckknight

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3101 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a1c9c525330ae489c5ad124818ea42097b0d3b73 1 parent 22da62f
@adrianholovaty adrianholovaty authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 django/utils/text.py
View
10 django/utils/text.py
@@ -109,3 +109,13 @@ def fix(match):
s = s.replace("'", "\\'")
return str(ustring_re.sub(fix, s))
+smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
+def smart_split(text):
+ for bit in smart_split_re.finditer(text):
+ bit = bit.group(0)
+ if bit[0] == '"':
+ yield (bit[1:-1].replace('\\"', '"').replace('\\\\', '\\'), True)
+ elif bit[0] == "'":
+ yield (bit[1:-1].replace("\\'", "'").replace("\\\\", "\\"), True)
+ else:
+ yield (bit, False)
Please sign in to comment.
Something went wrong with that request. Please try again.