Project

General

Profile

« Previous | Next » 

Revision 856

strings.py: Added is_multiline() and one_line() for removing extra newlines from single-line strings

View differences:

lib/strings.py
10 10

  
11 11
def ensure_newl(str_): return str_.rstrip()+'\n'
12 12

  
13
def is_multiline(str_):
14
    newl_idx = str_.find('\n')
15
    return newl_idx >= 0 and newl_idx != len(str_)-1 # has newline before end
16

  
17
def one_line(str_):
18
    if is_multiline(str_): return str_
19
    else: return str_.rstrip()
20

  
13 21
def std_newl(str_): return str_.replace('\r\n', '\n').replace('\r', '\n')
14 22

  
15 23
def cleanup(str_): return std_newl(str_.strip())

Also available in: Unified diff