Normalize a list of protocol strings: trim, lowercase, deduplicate, skip empty.
(protocols: &[String])
| 309 | |
| 310 | /// Normalize a list of protocol strings: trim, lowercase, deduplicate, skip empty. |
| 311 | pub fn normalize_protocols(protocols: &[String]) -> Vec<String> { |
| 312 | let mut normalized = Vec::new(); |
| 313 | let mut seen = HashSet::new(); |
| 314 | |
| 315 | for protocol in protocols { |
| 316 | let candidate = protocol.trim().to_ascii_lowercase(); |
| 317 | if candidate.is_empty() { |
| 318 | continue; |
| 319 | } |
| 320 | if seen.insert(candidate.clone()) { |
| 321 | normalized.push(candidate); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | normalized |
| 326 | } |
| 327 | |
| 328 | #[cfg(test)] |
| 329 | mod tests { |