MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / sanitize_name

Function sanitize_name

crates/chat-cli/src/cli/chat/tool_manager.rs:1876–1900  ·  view source on GitHub ↗
(orig: String, regex: &regex::Regex, hasher: &mut impl Hasher)

Source from the content-addressed store, hash-verified

1874}
1875
1876fn sanitize_name(orig: String, regex: &regex::Regex, hasher: &mut impl Hasher) -> String {
1877 if regex.is_match(&orig) && !orig.contains(NAMESPACE_DELIMITER) {
1878 return orig;
1879 }
1880 let sanitized: String = orig
1881 .chars()
1882 .filter(|c| c.is_ascii_alphabetic() || c.is_ascii_digit() || *c == '_')
1883 .collect::<String>()
1884 .replace(NAMESPACE_DELIMITER, "");
1885 if sanitized.is_empty() {
1886 hasher.write(orig.as_bytes());
1887 let hash = format!("{:03}", hasher.finish() % 1000);
1888 return format!("a{}", hash);
1889 }
1890 match sanitized.chars().next() {
1891 Some(c) if c.is_ascii_alphabetic() => sanitized,
1892 Some(_) => {
1893 format!("a{}", sanitized)
1894 },
1895 None => {
1896 hasher.write(orig.as_bytes());
1897 format!("a{}", hasher.finish())
1898 },
1899 }
1900}
1901
1902fn queue_success_message(name: &str, time_taken: &str, output: &mut impl Write) -> eyre::Result<()> {
1903 Ok(queue!(

Callers 2

process_tool_specsFunction · 0.85

Calls 4

is_emptyMethod · 0.45
writeMethod · 0.45
as_bytesMethod · 0.45
nextMethod · 0.45

Tested by 1