22 lines
533 B
Python
22 lines
533 B
Python
import re
|
|
import random
|
|
|
|
re_newline = re.compile('\r?\n')
|
|
|
|
def find_newlines(text):
|
|
return (m.end(0) for m in re_newline.finditer(text))
|
|
|
|
def iter_lines(text):
|
|
start = 0
|
|
for m in re_newline.finditer(text):
|
|
end = m.end(0)
|
|
yield (start, text[start:end])
|
|
start = m.end(0)
|
|
if start < len(text) - 1:
|
|
yield (start, text[start:])
|
|
|
|
def censor_text(text):
|
|
def random_chr():
|
|
return chr(random.randint(9728, 9983))
|
|
return ''.join(random_chr() if c.isalnum() else c for c in text)
|