Split a compound name into individual words. Handles camelCase, `PascalCase`, and `snake_case`: - `getUserName` → `["get", "User", "Name"]` - `process_request` → `["process", "request"]` - `MAX_RETRIES` → `["MAX", "RETRIES"]`
(name: &str)
| 746 | /// - `process_request` → `["process", "request"]` |
| 747 | /// - `MAX_RETRIES` → `["MAX", "RETRIES"]` |
| 748 | fn split_compound(name: &str) -> Vec<&str> { |
| 749 | if name.contains('_') { |
| 750 | return name.split('_').filter(|s| !s.is_empty()).collect(); |
| 751 | } |
| 752 | |
| 753 | // camelCase / PascalCase splitting |
| 754 | let bytes = name.as_bytes(); |
| 755 | let mut parts = Vec::new(); |
| 756 | let mut start = 0; |
| 757 | |
| 758 | for i in 1..bytes.len() { |
| 759 | let cur = bytes[i] as char; |
| 760 | let prev = bytes[i - 1] as char; |
| 761 | |
| 762 | // Split at lowercase→uppercase boundary (e.g. getUser → get|User) |
| 763 | let boundary = prev.is_ascii_lowercase() && cur.is_ascii_uppercase(); |
| 764 | // Split at uppercase→uppercase+lowercase (e.g. XMLParser → XML|Parser) |
| 765 | let acronym_end = i + 1 < bytes.len() |
| 766 | && prev.is_ascii_uppercase() |
| 767 | && cur.is_ascii_uppercase() |
| 768 | && (bytes[i + 1] as char).is_ascii_lowercase(); |
| 769 | |
| 770 | if boundary || acronym_end { |
| 771 | if i > start { |
| 772 | parts.push(&name[start..i]); |
| 773 | } |
| 774 | start = i; |
| 775 | } |
| 776 | } |
| 777 | if start < name.len() { |
| 778 | parts.push(&name[start..]); |
| 779 | } |
| 780 | parts |
| 781 | } |
| 782 | |
| 783 | /// Returns `true` if `word` looks like CamelCase. |
| 784 | /// |
no test coverage detected