File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -822,6 +822,39 @@ impl char {
822
822
}
823
823
}
824
824
825
+ /// Returns `true` if this `char` has the general category for titlecase letters.
826
+ ///
827
+ /// Titlecase letters (code points with the general category of `Lt`) are described in Chapter 4
828
+ /// (Character Properties) of the [Unicode Standard] and specified in the [Unicode Character
829
+ /// Database][ucd] [`UnicodeData.txt`].
830
+ ///
831
+ /// [Unicode Standard]: https://www.unicode.org/versions/latest/
832
+ /// [ucd]: https://www.unicode.org/reports/tr44/
833
+ /// [`UnicodeData.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
834
+ ///
835
+ /// # Examples
836
+ ///
837
+ /// Basic usage:
838
+ ///
839
+ /// ```
840
+ /// #![feature(titlecase)]
841
+ /// assert!('Dž'.is_titlecase());
842
+ /// assert!('ᾨ'.is_titlecase());
843
+ /// assert!(!'D'.is_titlecase());
844
+ /// assert!(!'z'.is_titlecase());
845
+ /// assert!(!'中'.is_titlecase());
846
+ /// assert!(!' '.is_titlecase());
847
+ /// ```
848
+ #[ must_use]
849
+ #[ unstable( feature = "titlecase" , issue = "none" ) ]
850
+ #[ inline]
851
+ pub fn is_titlecase ( self ) -> bool {
852
+ match self {
853
+ '\0' ..='\u{01C4}' => false ,
854
+ _ => self . is_cased ( ) && !self . is_lowercase ( ) && !self . is_uppercase ( ) ,
855
+ }
856
+ }
857
+
825
858
/// Returns `true` if this `char` has the `Uppercase` property.
826
859
///
827
860
/// `Uppercase` is described in Chapter 4 (Character Properties) of the [Unicode Standard] and
Original file line number Diff line number Diff line change @@ -61,6 +61,17 @@ fn test_is_lowercase() {
61
61
assert ! ( !'P' . is_lowercase( ) ) ;
62
62
}
63
63
64
+ #[ test]
65
+ fn test_is_titlecase ( ) {
66
+ assert ! ( 'Dž' . is_titlecase( ) ) ;
67
+ assert ! ( 'ᾨ' . is_titlecase( ) ) ;
68
+ assert ! ( !'h' . is_titlecase( ) ) ;
69
+ assert ! ( !'ä' . is_titlecase( ) ) ;
70
+ assert ! ( !'ß' . is_titlecase( ) ) ;
71
+ assert ! ( !'Ö' . is_titlecase( ) ) ;
72
+ assert ! ( !'T' . is_titlecase( ) ) ;
73
+ }
74
+
64
75
#[ test]
65
76
fn test_is_uppercase ( ) {
66
77
assert ! ( !'h' . is_uppercase( ) ) ;
@@ -70,6 +81,26 @@ fn test_is_uppercase() {
70
81
assert ! ( 'T' . is_uppercase( ) ) ;
71
82
}
72
83
84
+ #[ test]
85
+ fn titlecase_fast_path ( ) {
86
+ for c in '\0' ..='\u{01C4}' {
87
+ assert ! ( !( c. is_cased( ) && !c. is_lowercase( ) && !c. is_uppercase( ) ) )
88
+ }
89
+ }
90
+
91
+ #[ test]
92
+ fn at_most_one_case ( ) {
93
+ for c in '\0' ..='\u{10FFFF}' {
94
+ assert_eq ! (
95
+ !c. is_cased( ) as u8
96
+ + c. is_lowercase( ) as u8
97
+ + c. is_uppercase( ) as u8
98
+ + c. is_titlecase( ) as u8 ,
99
+ 1
100
+ ) ;
101
+ }
102
+ }
103
+
73
104
#[ test]
74
105
fn test_is_whitespace ( ) {
75
106
assert ! ( ' ' . is_whitespace( ) ) ;
You can’t perform that action at this time.
0 commit comments