mirror of
https://github.com/openai/codex.git
synced 2026-11-01 19:33:35 +00:00
21 lines
562 B
Rust
21 lines
562 B
Rust
pub fn sanitize_name(name: &str) -> String {
|
|
sanitize_slug(name).replace("-", "_")
|
|
}
|
|
|
|
fn sanitize_slug(name: &str) -> String {
|
|
let mut normalized = String::with_capacity(name.len());
|
|
for character in name.chars() {
|
|
if character.is_ascii_alphanumeric() {
|
|
normalized.push(character.to_ascii_lowercase());
|
|
} else {
|
|
normalized.push('-');
|
|
}
|
|
}
|
|
let normalized = normalized.trim_matches('-');
|
|
if normalized.is_empty() {
|
|
"app".to_string()
|
|
} else {
|
|
normalized.to_string()
|
|
}
|
|
}
|