Sentenize converts and normalizes string into a sentence.
(str string)
| 27 | |
| 28 | // Sentenize converts and normalizes string into a sentence. |
| 29 | func Sentenize(str string) string { |
| 30 | str = strings.TrimSpace(str) |
| 31 | if str == "" { |
| 32 | return "" |
| 33 | } |
| 34 | |
| 35 | str = UcFirst(str) |
| 36 | |
| 37 | lastChar := str[len(str)-1:] |
| 38 | if lastChar != "." && lastChar != "?" && lastChar != "!" { |
| 39 | return str + "." |
| 40 | } |
| 41 | |
| 42 | return str |
| 43 | } |
| 44 | |
| 45 | // Sanitize sanitizes `str` by removing all characters satisfying `removePattern`. |
| 46 | // Returns an error if the pattern is not valid regex string. |
searching dependent graphs…