1 /// Returns the index of the character after the first camel-case component of `s`.
3 pub fn until(s: &str) -> usize {
4 let mut iter = s.char_indices();
5 if let Some((_, first)) = iter.next() {
6 if !first.is_uppercase() {
21 } else if c.is_uppercase() {
24 } else if !c.is_lowercase() {
28 if up { last_i } else { s.len() }
31 /// Returns index of the last camel-case component of `s`.
33 pub fn from(s: &str) -> usize {
34 let mut iter = s.char_indices().rev();
35 if let Some((_, first)) = iter.next() {
36 if !first.is_lowercase() {
43 let mut last_i = s.len();
49 } else if !c.is_lowercase() {
52 } else if c.is_lowercase() {
54 } else if c.is_uppercase() {
65 use super::{from, until};
69 assert_eq!(from("AbcDef"), 0);
70 assert_eq!(from("Abc"), 0);
71 assert_eq!(from("ABcd"), 0);
72 assert_eq!(from("ABcdEf"), 0);
73 assert_eq!(from("AabABcd"), 0);
78 assert_eq!(from("abcDef"), 3);
79 assert_eq!(from("aDbc"), 1);
80 assert_eq!(from("aabABcd"), 3);
85 assert_eq!(from("AbcDef_"), 7);
86 assert_eq!(from("AbcDD"), 5);
91 assert_eq!(from("ABCD"), 4);
96 assert_eq!(until("AbcDef"), 6);
97 assert_eq!(until("Abc"), 3);
102 assert_eq!(until("abcDef"), 0);
103 assert_eq!(until("aDbc"), 0);
108 assert_eq!(until("AbcDef_"), 6);
109 assert_eq!(until("CallTypeC"), 8);
110 assert_eq!(until("AbcDD"), 3);
115 assert_eq!(until("ABCD"), 0);