perfect-postcode/server-rs/src/utils.rs
2026-03-15 14:05:34 +00:00

22 lines
756 B
Rust

mod grid_index;
mod hash;
mod interned_column;
mod llm;
pub use grid_index::GridIndex;
pub use hash::{generate_priorities, splitmix64_hash};
pub use interned_column::InternedColumn;
pub use llm::{extract_gemini_content, gemini_chat};
/// Normalize a UK postcode: uppercase, strip spaces, insert canonical space before inward code.
/// e.g. "e142dg" → "E14 2DG", "E14 2DG" → "E14 2DG", "EC1A1BB" → "EC1A 1BB"
pub fn normalize_postcode(raw: &str) -> String {
let stripped: String = raw.chars().filter(|c| !c.is_whitespace()).collect();
let upper = stripped.to_uppercase();
if upper.len() >= 5 {
let (outward, inward) = upper.split_at(upper.len() - 3);
format!("{} {}", outward, inward)
} else {
upper
}
}