| 1 | #![no_std] |
| 2 | extern crate allocrust-analyzer cargo unicode-casing 0.1.1 alloc/; |
| 3 | |
| 4 | mod bool_trierust-analyzer cargo unicode-casing 0.1.1 bool_trie/; |
| 5 | mod tablesrust-analyzer cargo unicode-casing 0.1.1 tables/; |
| 6 | |
| 7 | use tablesrust-analyzer cargo unicode-casing 0.1.1 tables/::{conversionsrust-analyzer cargo unicode-casing 0.1.1 tables/conversions/, general_categoryrust-analyzer cargo unicode-casing 0.1.1 tables/general_category/}; |
| 8 | |
| 9 | pub trait CharExtrust-analyzer cargo unicode-casing 0.1.1 CharExt# { |
| 10 | /// Indicates whether a character is titlecased. |
| 11 | /// |
| 12 | /// 'Titlecase' is defined in terms of the Unicode General Category |
| 13 | /// 'Lt'. |
| 14 | fn is_titlecaserust-analyzer cargo unicode-casing 0.1.1 CharExt#is_titlecase().(self) -> bool; |
| 15 | |
| 16 | /// Converts a character to its titlecase equivalent. |
| 17 | /// |
| 18 | /// This performs complex unconditional mappings with no tailoring. |
| 19 | /// See `to_uppercase()` for references and more information. |
| 20 | /// |
| 21 | /// This differs from `to_uppercase()` since Unicode contains |
| 22 | /// digraphs and ligature characters. |
| 23 | /// For example, U+01F3 “dz” and U+FB01 “fi” |
| 24 | /// map to U+01F1 “DZ” and U+0046 U+0069 “Fi”, respectively. |
| 25 | /// |
| 26 | /// # Return value |
| 27 | /// |
| 28 | /// Returns an iterator which yields the characters corresponding to the |
| 29 | /// titlecase equivalent of the character. If no conversion is possible then |
| 30 | /// an iterator with just the input character is returned. |
| 31 | /// |
| 32 | /// Note that `is_titlecase` will not necessarily return `true` for the |
| 33 | /// yielded characters. |
| 34 | fn to_titlecaserust-analyzer cargo unicode-casing 0.1.1 CharExt#to_titlecase().(self) -> ToTitlecaserust-analyzer cargo unicode-casing 0.1.1 ToTitlecase#; |
| 35 | } |
| 36 | |
| 37 | impl CharExtrust-analyzer cargo unicode-casing 0.1.1 CharExt# for char { |
| 38 | #[inline] |
| 39 | fn is_titlecaserust-analyzer cargo unicode-casing 0.1.1 impl#[char][CharExt]is_titlecase().(self) -> bool { |
| 40 | general_categoryrust-analyzer cargo unicode-casing 0.1.1 tables/general_category/::Ltrust-analyzer cargo unicode-casing 0.1.1 tables/general_category/Lt().(self) |
| 41 | } |
| 42 | |
| 43 | #[inline] |
| 44 | fn to_titlecaserust-analyzer cargo unicode-casing 0.1.1 impl#[char][CharExt]to_titlecase().(self) -> ToTitlecaserust-analyzer cargo unicode-casing 0.1.1 ToTitlecase# { |
| 45 | ToTitlecaserust-analyzer cargo unicode-casing 0.1.1 ToTitlecase#(CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::newrust-analyzer cargo unicode-casing 0.1.1 impl#[CaseMappingIter]new().(conversionsrust-analyzer cargo unicode-casing 0.1.1 tables/conversions/::to_titlerust-analyzer cargo unicode-casing 0.1.1 tables/conversions/to_title().(self))) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | enum CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter# { |
| 50 | Threerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Three#(char, char, char), |
| 51 | Tworust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Two#(char, char), |
| 52 | Onerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#One#(char), |
| 53 | Zerorust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Zero#, |
| 54 | } |
| 55 | |
| 56 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter# { |
| 57 | type Itemrust-analyzer cargo unicode-casing 0.1.1 impl#[CaseMappingIter][Iterator]Item# = char; |
| 58 | fn nextrust-analyzer cargo unicode-casing 0.1.1 impl#[CaseMappingIter][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> { |
| 59 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 60 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Threerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Three#(a, b, c) => { |
| 61 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Tworust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Two#(b, c); |
| 62 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) |
| 63 | } |
| 64 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Tworust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Two#(b, c) => { |
| 65 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Onerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#One#(c); |
| 66 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) |
| 67 | } |
| 68 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Onerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#One#(c) => { |
| 69 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Zerorust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Zero#; |
| 70 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) |
| 71 | } |
| 72 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Zerorust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Zero# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | impl CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter# { |
| 78 | fn newrust-analyzer cargo unicode-casing 0.1.1 impl#[CaseMappingIter]new().(chars: [char; 3]) -> CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter# { |
| 79 | if chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\0' { |
| 80 | if chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\0' { |
| 81 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Onerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#One#(chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().) // Including if chars[0] == '\0' |
| 82 | } else { |
| 83 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Tworust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Two#(chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().) |
| 84 | } |
| 85 | } else { |
| 86 | CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#::Threerust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#Three#(chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., chars[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().) |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | pub struct ToTitlecaserust-analyzer cargo unicode-casing 0.1.1 ToTitlecase#(CaseMappingIterrust-analyzer cargo unicode-casing 0.1.1 CaseMappingIter#); |
| 92 | |
| 93 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ToTitlecaserust-analyzer cargo unicode-casing 0.1.1 ToTitlecase# { |
| 94 | type Itemrust-analyzer cargo unicode-casing 0.1.1 impl#[ToTitlecase][Iterator]Item# = char; |
| 95 | fn nextrust-analyzer cargo unicode-casing 0.1.1 impl#[ToTitlecase][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> { |
| 96 | self.0rust-analyzer cargo unicode-casing 0.1.1 ToTitlecase#0..nextrust-analyzer cargo unicode-casing 0.1.1 impl#[CaseMappingIter][Iterator]next().() |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #[cfg(test)] |
| 101 | mod testsrust-analyzer cargo unicode-casing 0.1.1 tests/ { |
| 102 | use superrust-analyzer cargo unicode-casing 0.1.1 crate/::*; |
| 103 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 104 | |
| 105 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 106 | fn test_is_titlecaserust-analyzer cargo unicode-casing 0.1.1 tests/test_is_titlecase().() { |
| 107 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().'A'.is_titlecaserust-analyzer cargo unicode-casing 0.1.1 impl#[char][CharExt]is_titlecase().()); |
| 108 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!('\u{1FFC}'.is_titlecaserust-analyzer cargo unicode-casing 0.1.1 impl#[char][CharExt]is_titlecase().()); |
| 109 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!('Dž'.is_titlecaserust-analyzer cargo unicode-casing 0.1.1 impl#[char][CharExt]is_titlecase().()); |
| 110 | } |
| 111 | |
| 112 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 113 | fn test_to_titlecaserust-analyzer cargo unicode-casing 0.1.1 tests/test_to_titlecase().() { |
| 114 | fn titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().(c: char) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char> { |
| 115 | c.to_titlecaserust-analyzer cargo unicode-casing 0.1.1 impl#[char][CharExt]to_titlecase().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 116 | } |
| 117 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('a'), ['A']); |
| 118 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('ö'), ['Ö']); |
| 119 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('ß'), ['S', 's']); // not ẞ: Latin capital letter sharp s |
| 120 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('ü'), ['Ü']); |
| 121 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('💩'), ['💩']); |
| 122 | |
| 123 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('σ'), ['Σ']); |
| 124 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('τ'), ['Τ']); |
| 125 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('ι'), ['Ι']); |
| 126 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('γ'), ['Γ']); |
| 127 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('μ'), ['Μ']); |
| 128 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('α'), ['Α']); |
| 129 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('ς'), ['Σ']); |
| 130 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('DŽ'), ['Dž']); |
| 131 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('fi'), ['F', 'i']); |
| 132 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(titlerust-analyzer cargo unicode-casing 0.1.1 tests/title().('ᾀ'), ['ᾈ']); |
| 133 | } |
| 134 | } |