pub fn WordsFromPascal(Text: &str) -> Vec<String>Expand description
use crate::Maintain::Source::Build::WordsFromPascal;
let words = WordsFromPascal("Development");
assert_eq!(words, vec!["development"]);use crate::Maintain::Source::Build::WordsFromPascal;
let words = WordsFromPascal("NodeEnvironment");
assert_eq!(words, vec!["node", "environment"]);use crate::Maintain::Source::Build::WordsFromPascal;
let words = WordsFromPascal("TauriAppsTauri");
assert_eq!(words, vec!["tauri", "apps", "tauri"]);Converts a PascalCase string into a vector of its lowercase constituent
words.
This function splits PascalCase strings into their individual words by detecting word boundaries where lowercase letters appear after uppercase letters. It handles common cases including:
- Simple words:
"Hello"→["hello"] - Standard PascalCase:
"HelloWorld"→["hello", "world"] - Multi-letter acronyms:
"TauriApps"→["tauri", "apps"]
The algorithm tracks when transitions occur from lowercase to uppercase to determine word boundaries.
§Parameters
Text- The PascalCase string to split
§Returns
A vector of lowercase strings representing the constituent words.
§Behavior
- Splits at boundaries where lowercase letters are followed by uppercase
- Handles consecutive uppercase letters as part of the same word
- Converts all words to lowercase
- Returns an empty vector for empty strings
§Examples
use crate::Maintain::Source::Build::WordsFromPascal;
assert_eq!(WordsFromPascal("Hello"), vec!["hello"]);
assert_eq!(WordsFromPascal("HelloWorld"), vec!["hello", "world"]);
assert_eq!(WordsFromPascal("NodeEnvironment"), vec!["node", "environment"]);
assert_eq!(WordsFromPascal("TauriAppsTauri"), vec!["tauri", "apps", "tauri"]);
assert_eq!(WordsFromPascal(""), Vec::<String>::new());§Edge Cases
- Empty string returns an empty vector
- Single character strings work correctly
- Strings with all lowercase are treated as a single word
- Strings with all uppercase are treated as a single word
§Algorithm
The function iterates through each character:
- If the character is uppercase:
- If we have accumulated lowercase characters, end the current word
- Add the uppercase character to the current word
- Track that we’re processing uppercase characters
- If the character is lowercase:
- Add to the current word
- Track that we’re processing lowercase characters
- After iteration, add the final word
This ensures that multi-letter sequences like “Apps” stay together while properly splitting “HelloWorld” into “hello” and “world”.