Commit 2e77beba authored by Andreas Jung's avatar Andreas Jung

regex free (tested)

parent 1a767309
...@@ -82,9 +82,9 @@ ...@@ -82,9 +82,9 @@
# attributions are listed in the accompanying credits file. # attributions are listed in the accompanying credits file.
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.10 $'[11:-2] __version__='$Revision: 1.11 $'[11:-2]
import regex import re
from string import atoi, atol, atof, join, split, strip from string import atoi, atol, atof, join, split, strip
from types import ListType, TupleType from types import ListType, TupleType
...@@ -93,17 +93,21 @@ def field2string(v): ...@@ -93,17 +93,21 @@ def field2string(v):
else: v=str(v) else: v=str(v)
return v return v
def field2text(v, nl=regex.compile('\r\n\|\n\r').search): def field2text(v, nl=re.compile('\r\n\|\n\r').search):
if hasattr(v,'read'): v=v.read() if hasattr(v,'read'): v=v.read()
else: v=str(v) else: v=str(v)
l=nl(v) mo = nl(v)
if l < 0: return v if mo is None: return v
l = mo.start(0)
r=[] r=[]
s=0 s=0
while l >= s: while l >= s:
r.append(v[s:l]) r.append(v[s:l])
s=l+2 s=l+2
l=nl(v,s) mo=nl(v,s)
if mo is None: l=-1
else: l=mo.start(0)
r.append(v[s:]) r.append(v[s:])
return join(r,'\n') return join(r,'\n')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment