66//!
77//! ## Definition of a word boundary
88//!
9- //! Word boundaries are defined as the "unicode words" defined in the
10- //! `unicode_segmentation` library, as well as within those words in this
11- //! manner:
9+ //! Word boundaries are defined by non-alphanumeric characters, as well as
10+ //! within those words in this manner:
1211//!
13- //! 1. All underscore characters are considered word boundaries.
14- //! 2. If an uppercase character is followed by lowercase letters, a word
12+ //! 1. If an uppercase character is followed by lowercase letters, a word
1513//! boundary is considered to be just prior to that uppercase character.
16- //! 3 . If multiple uppercase characters are consecutive, they are considered to
14+ //! 2 . If multiple uppercase characters are consecutive, they are considered to
1715//! be within a single word, except that the last will be part of the next word
18- //! if it is followed by lowercase characters (see rule 2 ).
16+ //! if it is followed by lowercase characters (see rule 1 ).
1917//!
2018//! That is, "HelloWorld" is segmented `Hello|World` whereas "XMLHttpRequest" is
2119//! segmented `XML|Http|Request`.
4038//! 8. Train-Case
4139#![ deny( missing_docs) ]
4240#![ forbid( unsafe_code) ]
41+ #![ no_std]
42+
43+ extern crate alloc;
4344
4445mod kebab;
4546mod lower_camel;
@@ -63,17 +64,7 @@ pub use upper_camel::{
6364 AsUpperCamelCase , AsUpperCamelCase as AsPascalCase , ToPascalCase , ToUpperCamelCase ,
6465} ;
6566
66- use std:: fmt;
67-
68- #[ cfg( feature = "unicode" ) ]
69- fn get_iterator ( s : & str ) -> unicode_segmentation:: UnicodeWords {
70- use unicode_segmentation:: UnicodeSegmentation ;
71- s. unicode_words ( )
72- }
73- #[ cfg( not( feature = "unicode" ) ) ]
74- fn get_iterator ( s : & str ) -> impl Iterator < Item = & str > {
75- s. split ( |letter : char | !letter. is_ascii_alphanumeric ( ) )
76- }
67+ use core:: fmt;
7768
7869fn transform < F , G > (
7970 s : & str ,
@@ -107,20 +98,12 @@ where
10798
10899 let mut first_word = true ;
109100
110- for word in get_iterator ( s ) {
101+ for word in s . split ( | c : char | !c . is_alphanumeric ( ) ) {
111102 let mut char_indices = word. char_indices ( ) . peekable ( ) ;
112103 let mut init = 0 ;
113104 let mut mode = WordMode :: Boundary ;
114105
115106 while let Some ( ( i, c) ) = char_indices. next ( ) {
116- // Skip underscore characters
117- if c == '_' {
118- if init == i {
119- init += 1 ;
120- }
121- continue ;
122- }
123-
124107 if let Some ( & ( next_i, next) ) = char_indices. peek ( ) {
125108 // The mode including the current character, assuming the
126109 // current character does not result in a word boundary.
@@ -132,9 +115,9 @@ where
132115 mode
133116 } ;
134117
135- // Word boundary after if next is underscore or current is
136- // not uppercase and next is uppercase
137- if next == '_' || ( next_mode == WordMode :: Lowercase && next. is_uppercase ( ) ) {
118+ // Word boundary after if current is not uppercase and next
119+ // is uppercase
120+ if next_mode == WordMode :: Lowercase && next. is_uppercase ( ) {
138121 if !first_word {
139122 boundary ( f) ?;
140123 }
0 commit comments