Skip to main content

split_code_identifier

Function split_code_identifier 

Source
pub fn split_code_identifier(text: &str) -> Vec<String>
Expand description

Split a code identifier into its constituent sub-words.

Handles camelCase, PascalCase, snake_case, SCREAMING_SNAKE_CASE, and mixed forms (e.g. HTML5Parser). Returns the lowercased parts; if there is only one part (i.e. the token cannot be split further) an empty Vec is returned so callers know no expansion is needed.

§Examples

assert_eq!(split_code_identifier("parseJsonConfig"), vec!["parse", "json", "config"]);
assert_eq!(split_code_identifier("my_func_name"),    vec!["my", "func", "name"]);
assert_eq!(split_code_identifier("HTML5Parser"),     vec!["html5", "parser"]);
assert_eq!(split_code_identifier("parser"),          Vec::<String>::new());