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.
10 /// Return the index of the character after the first camel-case component of
12 pub fn until(s: &str) -> usize {
13 let mut iter = s.char_indices();
14 if let Some((_, first)) = iter.next() {
15 if !first.is_uppercase() {
30 } else if c.is_uppercase() {
33 } else if !c.is_lowercase() {
44 /// Return index of the last camel-case component of `s`.
45 pub fn from(s: &str) -> usize {
46 let mut iter = s.char_indices().rev();
47 if let Some((_, first)) = iter.next() {
48 if !first.is_lowercase() {
55 let mut last_i = s.len();
61 } else if !c.is_lowercase() {
64 } else if c.is_lowercase() {
75 use super::{from, until};
79 assert_eq!(from("AbcDef"), 0);
80 assert_eq!(from("Abc"), 0);
85 assert_eq!(from("abcDef"), 3);
86 assert_eq!(from("aDbc"), 1);
91 assert_eq!(from("AbcDef_"), 7);
92 assert_eq!(from("AbcDD"), 5);
97 assert_eq!(from("ABCD"), 4);
102 assert_eq!(until("AbcDef"), 6);
103 assert_eq!(until("Abc"), 3);
108 assert_eq!(until("abcDef"), 0);
109 assert_eq!(until("aDbc"), 0);
114 assert_eq!(until("AbcDef_"), 6);
115 assert_eq!(until("CallTypeC"), 8);
116 assert_eq!(until("AbcDD"), 3);
121 assert_eq!(until("ABCD"), 0);