1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
11 /// Return the index of the character after the first camel-case component of
13 pub fn camel_case_until(s: &str) -> usize {
14 let mut iter = s.char_indices();
15 if let Some((_, first)) = iter.next() {
16 if !first.is_uppercase() {
31 } else if c.is_uppercase() {
34 } else if !c.is_lowercase() {
45 /// Return index of the last camel-case component of `s`.
46 pub fn camel_case_from(s: &str) -> usize {
47 let mut iter = s.char_indices().rev();
48 if let Some((_, first)) = iter.next() {
49 if !first.is_lowercase() {
56 let mut last_i = s.len();
62 } else if !c.is_lowercase() {
65 } else if c.is_lowercase() {
76 use super::{camel_case_from, camel_case_until};
80 assert_eq!(camel_case_from("AbcDef"), 0);
81 assert_eq!(camel_case_from("Abc"), 0);
86 assert_eq!(camel_case_from("abcDef"), 3);
87 assert_eq!(camel_case_from("aDbc"), 1);
92 assert_eq!(camel_case_from("AbcDef_"), 7);
93 assert_eq!(camel_case_from("AbcDD"), 5);
98 assert_eq!(camel_case_from("ABCD"), 4);
103 assert_eq!(camel_case_until("AbcDef"), 6);
104 assert_eq!(camel_case_until("Abc"), 3);
109 assert_eq!(camel_case_until("abcDef"), 0);
110 assert_eq!(camel_case_until("aDbc"), 0);
115 assert_eq!(camel_case_until("AbcDef_"), 6);
116 assert_eq!(camel_case_until("CallTypeC"), 8);
117 assert_eq!(camel_case_until("AbcDD"), 3);
122 assert_eq!(camel_case_until("ABCD"), 0);