hydrus/include/HydrusText.py

30 lines
788 B
Python
Raw Normal View History

2017-12-13 22:33:07 +00:00
import re
re_newlines = re.compile( '[\r\n]+', re.UNICODE )
re_multiple_spaces = re.compile( '\\s+', re.UNICODE )
re_trailing_space = re.compile( '\\s+$', re.UNICODE )
re_leading_space = re.compile( '^\\s+', re.UNICODE )
re_leading_space_or_garbage = re.compile( '^(\\s|-|system:)+', re.UNICODE )
re_leading_single_colon = re.compile( '^:(?!:)', re.UNICODE )
def DeserialiseNewlinedTexts( text ):
text = text.replace( '\r', '' )
texts = text.split( '\n' )
texts = [ StripTrailingAndLeadingSpaces( line ) for line in texts ]
texts = [ line for line in texts if line != '' ]
return texts
def StripTrailingAndLeadingSpaces( t ):
t = re_trailing_space.sub( '', t )
t = re_leading_space.sub( '', t )
return t