Changeset 3111
- Timestamp:
- 06/07/06 23:26:23 (2 years ago)
- Files:
-
- django/trunk/django/utils/text.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/utils/text.py
r3101 r3111 112 112 smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)') 113 113 def smart_split(text): 114 """ 115 Generator that splits a string by spaces, leaving quoted phrases together. 116 Supports both single and double quotes, and supports escaping quotes with 117 backslashes. In the output, strings will keep their initial and trailing 118 quote marks. 119 >>> list(smart_split('This is "a person\'s" test.')) 120 ['This', 'is', '"a person\'s"', 'test.'] 121 """ 114 122 for bit in smart_split_re.finditer(text): 115 123 bit = bit.group(0) 116 124 if bit[0] == '"': 117 yield (bit[1:-1].replace('\\"', '"').replace('\\\\', '\\'), True)125 yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"' 118 126 elif bit[0] == "'": 119 yield (bit[1:-1].replace("\\'", "'").replace("\\\\", "\\"), True)127 yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'" 120 128 else: 121 yield (bit, False)129 yield bit
