| 208 | | ['This', 'is', '"a person\'s"', 'test.'] |
|---|
| | 209 | [u'This', u'is', u'"a person\'s"', u'test.'] |
|---|
| | 210 | |
|---|
| | 211 | Even if quoted content is found in the middle of a phrase, it is considered |
|---|
| | 212 | part of the same phrase: |
|---|
| | 213 | |
|---|
| | 214 | >>> text = '''with thelist|filter:'A B'|another:"Y Z" as var''' |
|---|
| | 215 | >>> list(smart_split(text)) |
|---|
| | 216 | [u'with', u'thelist|filter:\'A B\'|another:"Y Z"', u'as', u'var'] |
|---|
| 212 | | bit = bit.group(0) |
|---|
| 213 | | if bit[0] == '"' and bit[-1] == '"': |
|---|
| 214 | | yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"' |
|---|
| 215 | | elif bit[0] == "'" and bit[-1] == "'": |
|---|
| 216 | | yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'" |
|---|
| 217 | | else: |
|---|
| 218 | | yield bit |
|---|
| | 221 | content = bit.group(1) |
|---|
| | 222 | if content: |
|---|
| | 223 | if content.startswith('"') and content.endswith('"'): |
|---|
| | 224 | content = u'"%s"' % content[1:-1].replace('\\"', '"')\ |
|---|
| | 225 | .replace('\\\\', '\\') |
|---|
| | 226 | elif content.startswith("'") and content.endswith("'"): |
|---|
| | 227 | content = u"'%s'" % content[1:-1].replace("\\'", "'")\ |
|---|
| | 228 | .replace("\\\\", "\\") |
|---|
| | 229 | contents.append(content) |
|---|
| | 230 | elif contents: |
|---|
| | 231 | yield ''.join(contents) |
|---|
| | 232 | contents = [] |
|---|
| | 233 | if contents: |
|---|
| | 234 | yield ''.join(contents) |
|---|