normalizeSanitizeSeparators converts common separators to hyphens and optionally converts underscores when they are not in the preserve list.
(result string, opts *SanitizeOptions)
| 120 | // normalizeSanitizeSeparators converts common separators to hyphens and optionally |
| 121 | // converts underscores when they are not in the preserve list. |
| 122 | func normalizeSanitizeSeparators(result string, opts *SanitizeOptions) string { |
| 123 | result = strings.ReplaceAll(result, ":", "-") |
| 124 | result = strings.ReplaceAll(result, "\\", "-") |
| 125 | result = strings.ReplaceAll(result, "/", "-") |
| 126 | result = strings.ReplaceAll(result, " ", "-") |
| 127 | if !slices.Contains(opts.PreserveSpecialChars, '_') { |
| 128 | result = strings.ReplaceAll(result, "_", "-") |
| 129 | } |
| 130 | return result |
| 131 | } |
| 132 | |
| 133 | // buildSanitizePreservePattern builds a regex character class of allowed characters. |
| 134 | func buildSanitizePreservePattern(opts *SanitizeOptions) string { |