| 1 | /// Normalize the given character name in place according to UAX44-LM2. |
| 2 | /// |
| 3 | /// See: https://unicode.org/reports/tr44/#UAX44-LM2 |
| 4 | pub fn character_name_normalizerust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize().(string: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) { |
| 5 | let bytes = unsafe { |
| 6 | // SAFETY: `character_name_normalize_bytes` guarantees that |
| 7 | // `bytes[..len]` is valid UTF-8. |
| 8 | string.as_mut_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_mut_vec().() |
| 9 | }; |
| 10 | let len = character_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize_bytes().(bytes).lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 11 | bytes.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(len); |
| 12 | } |
| 13 | |
| 14 | /// Normalize the given character name in place according to UAX44-LM2. |
| 15 | /// |
| 16 | /// The slice returned is guaranteed to be valid UTF-8 for all possible values |
| 17 | /// of `slice`. |
| 18 | /// |
| 19 | /// See: https://unicode.org/reports/tr44/#UAX44-LM2 |
| 20 | fn character_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize_bytes().(slice: &mut [u8]) -> &mut [u8] { |
| 21 | // According to Unicode 4.8, character names consist only of Latin |
| 22 | // capital letters A to Z, ASCII digits, ASCII space or ASCII hypen. |
| 23 | // Therefore, we can do very simplistic case folding and operate on the |
| 24 | // raw bytes, since everything is ASCII. Note that we don't actually know |
| 25 | // whether `slice` is all ASCII or not, so we drop all non-ASCII bytes. |
| 26 | let mut next_write = 0; |
| 27 | let mut prev_letter = false; |
| 28 | // let mut prev_space = true; |
| 29 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 30 | // SAFETY ARGUMENT: To guarantee that the resulting slice is valid |
| 31 | // UTF-8, we ensure that the slice contains only ASCII bytes. In |
| 32 | // particular, we drop every non-ASCII byte from the normalized string. |
| 33 | let b = slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 34 | if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b' ' { |
| 35 | // Drop spaces. |
| 36 | } else if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'_' { |
| 37 | // Drop the underscore. |
| 38 | } else if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-' { |
| 39 | let medial = prev_letter |
| 40 | && slice.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1).map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |b| b.is_ascii_alphabeticrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_alphabetic().()); |
| 41 | let mut keep_hyphen = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().medial; |
| 42 | // We want to keep the hypen only if it isn't medial. However, |
| 43 | // there is one exception. We need to keep the hypen in the |
| 44 | // character (U+1180) named `HANGUL JUNGSEONG O-E`. So we check for |
| 45 | // that here. |
| 46 | let next_e = |
| 47 | slice.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1).map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |&b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'E' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'e'); |
| 48 | // More characters after the final E are fine, as long as they are |
| 49 | // underscores and spaces. |
| 50 | let rest_empty = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 51 | || slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|&b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b' ' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'_'); |
| 52 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().keep_hyphen && next_e && rest_empty { |
| 53 | keep_hyphen = slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().b"hanguljungseongo"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 54 | } |
| 55 | if keep_hyphen { |
| 56 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b; |
| 57 | next_write rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 58 | } |
| 59 | } else if b'A' rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().b && b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().b'Z' { |
| 60 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().(b'a' rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().b'A'); |
| 61 | next_write rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 62 | } else if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().0x7F { |
| 63 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b; |
| 64 | next_write rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 65 | } |
| 66 | // prev_space = false; |
| 67 | prev_letter = b.is_ascii_alphabeticrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_alphabetic().(); |
| 68 | } |
| 69 | &mut slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). |
| 70 | } |
| 71 | |
| 72 | /// Normalize the given symbolic name in place according to UAX44-LM3. |
| 73 | /// |
| 74 | /// A "symbolic name" typically corresponds to property names and property |
| 75 | /// value aliases. Note, though, that it should not be applied to property |
| 76 | /// string values. |
| 77 | /// |
| 78 | /// See: https://unicode.org/reports/tr44/#UAX44-LM2 |
| 79 | pub fn symbolic_name_normalizerust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize().(string: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) { |
| 80 | let bytes = unsafe { |
| 81 | // SAFETY: `symbolic_name_normalize_bytes` guarantees that |
| 82 | // `bytes[..len]` is valid UTF-8. |
| 83 | string.as_mut_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_mut_vec().() |
| 84 | }; |
| 85 | let len = symbolic_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize_bytes().(bytes).lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 86 | bytes.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(len); |
| 87 | } |
| 88 | |
| 89 | /// Normalize the given symbolic name in place according to UAX44-LM3. |
| 90 | /// |
| 91 | /// A "symbolic name" typically corresponds to property names and property |
| 92 | /// value aliases. Note, though, that it should not be applied to property |
| 93 | /// string values. |
| 94 | /// |
| 95 | /// The slice returned is guaranteed to be valid UTF-8 for all possible values |
| 96 | /// of `slice`. |
| 97 | /// |
| 98 | /// See: https://unicode.org/reports/tr44/#UAX44-LM3 |
| 99 | fn symbolic_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize_bytes().(slice: &mut [u8]) -> &mut [u8] { |
| 100 | // I couldn't find a place in the standard that specified that property |
| 101 | // names/aliases had a particular structure (unlike character names), but |
| 102 | // we assume that it's ASCII only and drop anything that isn't ASCII. |
| 103 | let mut start = 0; |
| 104 | let mut starts_with_is = false; |
| 105 | if slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().2 { |
| 106 | // Ignore any "is" prefix. |
| 107 | starts_with_is = slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().b"is"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 108 | || slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().b"IS"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 109 | || slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().b"iS"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 110 | || slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().b"Is"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 111 | if starts_with_is { |
| 112 | start = 2; |
| 113 | } |
| 114 | } |
| 115 | let mut next_write = 0; |
| 116 | for i in start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 117 | // SAFETY ARGUMENT: To guarantee that the resulting slice is valid |
| 118 | // UTF-8, we ensure that the slice contains only ASCII bytes. In |
| 119 | // particular, we drop every non-ASCII byte from the normalized string. |
| 120 | let b = slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 121 | if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b' ' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'_' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-' { |
| 122 | continue; |
| 123 | } else if b'A' rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().b && b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().b'Z' { |
| 124 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().(b'a' rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().b'A'); |
| 125 | next_write rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 126 | } else if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().0x7F { |
| 127 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b; |
| 128 | next_write rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 129 | } |
| 130 | } |
| 131 | // Special case: ISO_Comment has a 'isc' abbreviation. Since we generally |
| 132 | // ignore 'is' prefixes, the 'isc' abbreviation gets caught in the cross |
| 133 | // fire and ends up creating an alias for 'c' to 'ISO_Comment', but it |
| 134 | // is actually an alias for the 'Other' general category. |
| 135 | if starts_with_is && next_write rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 && slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'c' { |
| 136 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b'i'; |
| 137 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b's'; |
| 138 | slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = b'c'; |
| 139 | next_write = 3; |
| 140 | } |
| 141 | &mut slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#next_write]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). |
| 142 | } |
| 143 | |
| 144 | #[cfg(test)] |
| 145 | mod testsrust-analyzer cargo ucd-util 0.2.2 name/tests/ { |
| 146 | use superrust-analyzer cargo ucd-util 0.2.2 name/::{ |
| 147 | character_name_normalizerust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize()., character_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize_bytes()., |
| 148 | symbolic_name_normalizerust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize()., symbolic_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize_bytes()., |
| 149 | }; |
| 150 | |
| 151 | fn char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().(s: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 152 | let mut s = s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 153 | character_name_normalizerust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize().(&mut s); |
| 154 | s |
| 155 | } |
| 156 | |
| 157 | fn sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().(s: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 158 | let mut s = s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 159 | symbolic_name_normalizerust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize().(&mut s); |
| 160 | s |
| 161 | } |
| 162 | |
| 163 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 164 | fn char_normalizerust-analyzer cargo ucd-util 0.2.2 name/tests/char_normalize().() { |
| 165 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("HANGUL JUNGSEONG O-E"), "hanguljungseongo-e"); |
| 166 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("HANGUL JUNGSEONG O-E _"), "hanguljungseongo-e"); |
| 167 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("zero-width space"), "zerowidthspace"); |
| 168 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("zerowidthspace"), "zerowidthspace"); |
| 169 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("ZERO WIDTH SPACE"), "zerowidthspace"); |
| 170 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("TIBETAN MARK TSA -PHRU"), "tibetanmarktsa-phru"); |
| 171 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(char_normrust-analyzer cargo ucd-util 0.2.2 name/tests/char_norm().("tibetan_letter_-a"), "tibetanletter-a"); |
| 172 | } |
| 173 | |
| 174 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 175 | fn sym_normalizerust-analyzer cargo ucd-util 0.2.2 name/tests/sym_normalize().() { |
| 176 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("Line_Break"), "linebreak"); |
| 177 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("Line-break"), "linebreak"); |
| 178 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("linebreak"), "linebreak"); |
| 179 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("BA"), "ba"); |
| 180 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("ba"), "ba"); |
| 181 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("Greek"), "greek"); |
| 182 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("isGreek"), "greek"); |
| 183 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("IS_Greek"), "greek"); |
| 184 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("isc"), "isc"); |
| 185 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("is c"), "isc"); |
| 186 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("is_c"), "isc"); |
| 187 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sym_normrust-analyzer cargo ucd-util 0.2.2 name/tests/sym_norm().("IS"), "is"); |
| 188 | } |
| 189 | |
| 190 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 191 | fn valid_utf8_characterrust-analyzer cargo ucd-util 0.2.2 name/tests/valid_utf8_character().() { |
| 192 | let mut x = b"abc\xFFxyz".to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 193 | let y = character_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/character_name_normalize_bytes().(&mut x); |
| 194 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(y, b"abcxyz"); |
| 195 | } |
| 196 | |
| 197 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 198 | fn valid_utf8_symbolicrust-analyzer cargo ucd-util 0.2.2 name/tests/valid_utf8_symbolic().() { |
| 199 | let mut x = b"abc\xFFxyz".to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 200 | let y = symbolic_name_normalize_bytesrust-analyzer cargo ucd-util 0.2.2 name/symbolic_name_normalize_bytes().(&mut x); |
| 201 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(y, b"abcxyz"); |
| 202 | } |
| 203 | } |