graphforge_core/
identifier.rs1pub const MAX_GRAPH_IDENTIFIER_BYTES: usize = 255;
5
6#[must_use]
8pub fn is_graph_identifier(value: &str) -> bool {
9 if value.len() > MAX_GRAPH_IDENTIFIER_BYTES {
10 return false;
11 }
12 let mut characters = value.chars();
13 characters
14 .next()
15 .is_some_and(|first| first == '_' || first.is_alphabetic())
16 && characters.all(|character| character == '_' || character.is_alphanumeric())
17}
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22
23 #[test]
24 fn unicode_identifier_limit_is_encoded_bytes() {
25 let at_limit = format!("A{}", "é".repeat(127));
26 let over_limit = format!("A{}x", "é".repeat(127));
27 assert_eq!(at_limit.len(), 255);
28 assert_eq!(over_limit.len(), 256);
29 assert!(is_graph_identifier(&at_limit));
30 assert!(!is_graph_identifier(&over_limit));
31 }
32}