2007-06-02 | paulb | raw annotate files changeset graph | SQL literal detection routines. |
1 #!/usr/bin/env python 2 3 import re 4 query = re.compile("(?P<non_literal>[^']+)|(?P<literal>'(?:[^']|(?:''))*')") 5 6 def parseString(s): 7 regions = [] 8 first = 1 9 for match in query.finditer(s): 10 non_literal, literal = match.groups() 11 if first and literal: 12 regions.append("") 13 if non_literal: 14 regions.append(non_literal) 15 elif literal: 16 regions.append(literal) 17 first = 0 18 19 return regions 20 21 # vim: tabstop=4 expandtab shiftwidth=4