keyNormalizer returns a function that applies the configured normalization rules to a question before it is used as a cache key. Trim runs before lowercase: trim only removes leading/trailing whitespace and is unaffected by case, so the order is irrelevant for correctness, but trim-first keeps the l
(caseSensitive, trimSpaces bool)
| 245 | // correctness, but trim-first keeps the lowercased map keys tighter on |
| 246 | // inputs like " HELLO\n". |
| 247 | func keyNormalizer(caseSensitive, trimSpaces bool) func(string) string { |
| 248 | return func(s string) string { |
| 249 | if trimSpaces { |
| 250 | s = strings.TrimSpace(s) |
| 251 | } |
| 252 | if !caseSensitive { |
| 253 | s = strings.ToLower(s) |
| 254 | } |
| 255 | return s |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | // loadFromFile decodes path into entries. A missing file is not an error |
| 260 | // and leaves entries empty. |