Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored June 07, 2006

Showing 1 changed file with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. 10  django/utils/text.py
10  django/utils/text.py
@@ -109,3 +109,13 @@ def fix(match):
109 109
     s = s.replace("'", "\\'")
110 110
     return str(ustring_re.sub(fix, s))
111 111
 
  112
+smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
  113
+def smart_split(text):
  114
+    for bit in smart_split_re.finditer(text):
  115
+        bit = bit.group(0)
  116
+        if bit[0] == '"':
  117
+            yield (bit[1:-1].replace('\\"', '"').replace('\\\\', '\\'), True)
  118
+        elif bit[0] == "'":
  119
+            yield (bit[1:-1].replace("\\'", "'").replace("\\\\", "\\"), True)
  120
+        else:
  121
+            yield (bit, False)

0 notes on commit a1c9c52

Please sign in to comment.
Something went wrong with that request. Please try again.