comparison textshaper/split.py @ 50:1284c99a94fa

stubbing
author Jeff Hammel <k0scist@gmail.com>
date Sat, 16 May 2015 21:02:07 -0700
parents 03ce88daa98d
children c3b69728f291
comparison
equal deleted inserted replaced
49:643c8e92e71e 50:1284c99a94fa
9 import re 9 import re
10 import string 10 import string
11 import sys 11 import sys
12 12
13 13
14 def findall(sub, _string): 14 def findall(_string, sub):
15 """find all occurances of `sub` in _string""" 15 """find all occurances of `sub` in _string"""
16 16
17 retval = [] 17 retval = []
18 index = 0 18 index = 0
19 while True: 19 while True:
20 try: 20 try:
21 index = _string.index(sub, index) 21 index = _string.index(sub, index)
22 retval.append(index) 22 retval.append(index)
23 index += 1 23 index += len(sub)
24 except ValueError: 24 except ValueError:
25 return retval 25 return retval
26 26
27 def findindices(_string, values):
28 """
29 returns ordered list of 2-tuples:
30 (index, value)
31 """
32
33 def split_sentences(text, ends='.?!'):
34 """split a text into sentences"""
27 35
28 def split_paragraphs(text): 36 def split_paragraphs(text):
29 37
30 lines = [line.strip() for line in text.strip().splitlines()] 38 lines = [line.strip() for line in text.strip().splitlines()]
31 lines = [line if line else '\n' 39 lines = [line if line else '\n'