Split user input into initial whitespace, escape character, function part and the rest.
(line, pattern=None)
| 51 | |
| 52 | |
| 53 | def split_user_input(line, pattern=None): |
| 54 | """Split user input into initial whitespace, escape character, function part |
| 55 | and the rest. |
| 56 | """ |
| 57 | # We need to ensure that the rest of this routine deals only with unicode |
| 58 | encoding = get_stream_enc(sys.stdin, 'utf-8') |
| 59 | line = py3compat.cast_unicode(line, encoding) |
| 60 | |
| 61 | if pattern is None: |
| 62 | pattern = line_split |
| 63 | match = pattern.match(line) |
| 64 | if not match: |
| 65 | # print "match failed for line '%s'" % line |
| 66 | try: |
| 67 | ifun, the_rest = line.split(None,1) |
| 68 | except ValueError: |
| 69 | # print "split failed for line '%s'" % line |
| 70 | ifun, the_rest = line, u'' |
| 71 | pre = re.match(r'^(\s*)(.*)',line).groups()[0] |
| 72 | esc = "" |
| 73 | else: |
| 74 | pre, esc, ifun, the_rest = match.groups() |
| 75 | |
| 76 | #print 'line:<%s>' % line # dbg |
| 77 | #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest) # dbg |
| 78 | return pre, esc or '', ifun.strip(), the_rest.lstrip() |
| 79 | |
| 80 | |
| 81 | class LineInfo(object): |
no test coverage detected