(text string)
| 9 | ) |
| 10 | |
| 11 | func Cleanup(text string) string { |
| 12 | // windows new line, Github, really ? |
| 13 | text = strings.Replace(text, "\r\n", "\n", -1) |
| 14 | |
| 15 | // remove all unicode control characters except |
| 16 | // '\n', '\r' and '\t' |
| 17 | t := runes.Remove(runes.Predicate(func(r rune) bool { |
| 18 | switch r { |
| 19 | case '\r', '\n', '\t': |
| 20 | return false |
| 21 | } |
| 22 | return unicode.IsControl(r) |
| 23 | })) |
| 24 | sanitized, _, err := transform.String(t, text) |
| 25 | if err != nil { |
| 26 | // transform.String should never return an error as our transformer doesn't returns one. |
| 27 | // Confirmed with fuzzing. |
| 28 | panic(err) |
| 29 | } |
| 30 | |
| 31 | // trim extra new line not displayed in the github UI but still present in the data |
| 32 | return strings.TrimSpace(sanitized) |
| 33 | } |
| 34 | |
| 35 | func CleanupOneLine(text string) string { |
| 36 | // remove all unicode control characters *including* |
no test coverage detected