untools/
utils.rs

1
2
3/// Checks if a string is in camelCase or PascalCase format.
4///
5/// # Arguments
6///
7/// * `name` - A string slice that holds the variable name to be checked.
8///
9/// # Returns
10///
11/// A boolean indicating whether the input string is in camelCase or PascalCase format.
12///
13pub(crate) fn is_camel_or_pascal_case(name: &str) -> bool {
14    let mut has_uppercase = false;
15    let mut has_lowercase = false;
16
17    let mut chars = name.chars().peekable();
18
19    if let Some(first_char) = chars.peek() {
20        if first_char.is_lowercase() {
21            has_lowercase = true;
22        } else if first_char.is_uppercase() {
23            has_uppercase = true;
24        }
25    }
26
27    while let Some(c) = chars.next() {
28        if c.is_uppercase() {
29            has_uppercase = true;
30        } else if c.is_lowercase() {
31            has_lowercase = true;
32        } else if c.is_whitespace() || c == '_' {
33            // Ignore whitespaces and underscores
34            continue;
35        }
36    }
37
38    has_uppercase && has_lowercase
39}
40
41/// Checks if a string starts with a digit.
42///
43/// # Arguments
44///
45/// * `name` - A string slice that holds the variable name to be checked.
46///
47/// # Returns
48///
49/// A boolean indicating whether the input string starts with a digit.
50///
51pub(crate) fn starts_with_digit(name: &str) -> bool {
52    if let Some(first_char) = name.chars().next() {
53        if first_char.is_ascii_digit() {
54            return false;
55        }
56    }
57    true
58}