fn character_name_normalize_bytes(slice: &mut [u8]) -> &mut [u8] {
    // According to Unicode 4.8, character names consist only of Latin
    // capital letters A to Z, ASCII digits, ASCII space or ASCII hypen.
    // Therefore, we can do very simplistic case folding and operate on the
    // raw bytes, since everything is ASCII. Note that we don't actually know
    // whether `slice` is all ASCII or not, so we drop all non-ASCII bytes.
    let mut next_write = 0;
    let mut prev_letter = false;
    // let mut prev_space = true;
    for i in 0..slice.len() {
        // SAFETY ARGUMENT: To guarantee that the resulting slice is valid
        // UTF-8, we ensure that the slice contains only ASCII bytes. In
        // particular, we drop every non-ASCII byte from the normalized string.
        let b = slice[i];
        if b == b' ' {
            // Drop spaces.
        } else if b == b'_' {
            // Drop the underscore.
        } else if b == b'-' {
            let medial = prev_letter
                && slice.get(i + 1).map_or(false, |b| b.is_ascii_alphabetic());
            let mut keep_hyphen = !medial;
            // We want to keep the hypen only if it isn't medial. However,
            // there is one exception. We need to keep the hypen in the
            // character (U+1180) named `HANGUL JUNGSEONG O-E`. So we check for
            // that here.
            let next_e =
                slice.get(i + 1).map_or(false, |&b| b == b'E' || b == b'e');
            // More characters after the final E are fine, as long as they are
            // underscores and spaces.
            let rest_empty = i + 2 >= slice.len()
                || slice[i + 2..].iter().all(|&b| b == b' ' || b == b'_');
            if !keep_hyphen && next_e && rest_empty {
                keep_hyphen = slice[..next_write] == b"hanguljungseongo"[..];
            }
            if keep_hyphen {
                slice[next_write] = b;
                next_write += 1;
            }
        } else if b'A' <= b && b <= b'Z' {
            slice[next_write] = b + (b'a' - b'A');
            next_write += 1;
        } else if b <= 0x7F {
            slice[next_write] = b;
            next_write += 1;
        }
        // prev_space = false;
        prev_letter = b.is_ascii_alphabetic();
    }
    &mut slice[..next_write]
}
/// Normalize the given character name in place according to UAX44-LM2.
///
/// The slice returned is guaranteed to be valid UTF-8 for all possible values
/// of `slice`.
///
/// See: https://unicode.org/reports/tr44/#UAX44-LM2
Normalize the given character name in place according to UAX44-LM2.
The slice returned is guaranteed to be valid UTF-8 for all possible values
of `slice`.


Normalize the given character name in place according to UAX44 - LM2 . The slice returned is guaranteed to be valid UTF - 8 for all possible values of ` slice ` .
fn character_name_normalize_bytes(slice: &mut [u8]) -> &mut [u8] {
    // According to Unicode 4.8, character names consist only of Latin
    // capital letters A to Z, ASCII digits, ASCII space or ASCII hypen.
    // Therefore, we can do very simplistic case folding and operate on the
    // raw bytes, since everything is ASCII. Note that we don't actually know
    // whether `slice` is all ASCII or not, so we drop all non-ASCII bytes.
    let mut next_write = 0;
    let mut prev_letter = false;
    // let mut prev_space = true;
    for i in 0..slice.len() {
        // SAFETY ARGUMENT: To guarantee that the resulting slice is valid
        // UTF-8, we ensure that the slice contains only ASCII bytes. In
        // particular, we drop every non-ASCII byte from the normalized string.
        let b = slice[i];
        if b == b' ' {
            // Drop spaces.
        } else if b == b'_' {
            // Drop the underscore.
        } else if b == b'-' {
            let medial = prev_letter
                && slice.get(i + 1).map_or(false, |b| b.is_ascii_alphabetic());
            let mut keep_hyphen = !medial;
            // We want to keep the hypen only if it isn't medial. However,
            // there is one exception. We need to keep the hypen in the
            // character (U+1180) named `HANGUL JUNGSEONG O-E`. So we check for
            // that here.
            let next_e =
                slice.get(i + 1).map_or(false, |&b| b == b'E' || b == b'e');
            // More characters after the final E are fine, as long as they are
            // underscores and spaces.
            let rest_empty = i + 2 >= slice.len()
                || slice[i + 2..].iter().all(|&b| b == b' ' || b == b'_');
            if !keep_hyphen && next_e && rest_empty {
                keep_hyphen = slice[..next_write] == b"hanguljungseongo"[..];
            }
            if keep_hyphen {
                slice[next_write] = b;
                next_write += 1;
            }
        } else if b'A' <= b && b <= b'Z' {
            slice[next_write] = b + (b'a' - b'A');
            next_write += 1;
        } else if b <= 0x7F {
            slice[next_write] = b;
            next_write += 1;
        }
        // prev_space = false;
        prev_letter = b.is_ascii_alphabetic();
    }
    &mut slice[..next_write]
}
fn character_name_normalize_bytes ( slice : & mut [ u8 ] ) -> & mut [ u8 ] { // According to Unicode 4.8, character names consist only of Latin // capital letters A to Z, ASCII digits, ASCII space or ASCII hypen. // Therefore, we can do very simplistic case folding and operate on the // raw bytes, since everything is ASCII. Note that we don't actually know // whether `slice` is all ASCII or not, so we drop all non-ASCII bytes. let mut next_write = 0 ; let mut prev_letter = false ; // let mut prev_space = true; for i in 0 .. slice . len ( ) { // SAFETY ARGUMENT: To guarantee that the resulting slice is valid // UTF-8, we ensure that the slice contains only ASCII bytes. In // particular, we drop every non-ASCII byte from the normalized string. let b = slice [ i ] ; if b == b' ' { // Drop spaces. } else if b == b'_' { // Drop the underscore. } else if b == b'-' { let medial = prev_letter && slice . get ( i + 1 ) . map_or ( false , | b | b . is_ascii_alphabetic ( ) ) ; let mut keep_hyphen = ! medial ; // We want to keep the hypen only if it isn't medial. However, // there is one exception. We need to keep the hypen in the // character (U+1180) named `HANGUL JUNGSEONG O-E`. So we check for // that here. let next_e = slice . get ( i + 1 ) . map_or ( false , | & b | b == b'E' || b == b'e' ) ; // More characters after the final E are fine, as long as they are // underscores and spaces. let rest_empty = i + 2 >= slice . len ( ) || slice [ i + 2 .. ] . iter ( ) . all ( | & b | b == b' ' || b == b'_' ) ; if ! keep_hyphen && next_e && rest_empty { keep_hyphen = slice [ .. next_write ] == b" " [ .. ] ; } if keep_hyphen { slice [ next_write ] = b ; next_write += 1 ; } } else if b'A' <= b && b <= b'Z' { slice [ next_write ] = b + ( b'a' - b'A' ) ; next_write += 1 ; } else if b <= 0x7F { slice [ next_write ] = b ; next_write += 1 ; } // prev_space = false; prev_letter = b . is_ascii_alphabetic ( ) ; } & mut slice [ .. next_write ] }
Normalize the given character name in place according to UAX44-LM2.
Normalize the given character name in place according to UAX44 - LM2 .
slice
&mut [u8]
slice
&mut [u8]