def spaces_round_second_hyphen_in_word(string): for word in get_words(string): base_word = word index = -1 hyphen_count = 0 while True: index = word.find('-', index + 1) if index == -1 or index + 1 >= len(word): break hyphen_count += 1 if hyphen_count > 1: word = insert_space(word, index + 1) word = insert_space(word, index) string = string.replace(base_word, word) break return string
def spaces_round_quote_phrase(string): index = -1 in_quote = False while True: index = string.find(u'"', index + 1) if index == -1 or index + 1 >= len(string): break in_quote = not in_quote if in_quote and index > 0 and not string[index - 1].isspace(): string = insert_space(string, index) index += 1 continue if not in_quote and index + 1 < len(string) and not string[index + 1].isspace(): string = insert_space(string, index + 1) index += 1 continue return string
def space_after_lowcase_before_upcase(string): index = -1 while True: index += 1 if index + 1 >= len(string): break if string[index].islower() and string[index + 1].isupper(): string = insert_space(string, index + 1) return string
def space_after_number_before_char(string): index = -1 while True: index += 1 if index + 1 >= len(string): break if string[index].isdigit() and string[index + 1].isalpha(): string = insert_space(string, index + 1) return string
def space_after_dot(string): index = -1 while True: index = string.find('.', index + 1) if index == -1 or index + 1 >= len(string): break if string[index + 1] != ' ': string = insert_space(string, index + 1) return string