diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-03-27 03:42:32 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-03-27 03:42:32 -0700 |
| commit | 10327d770eb19764d1e272d2f32a4f0e3edd9062 (patch) | |
| tree | cc70187f69116b4fb48aef1569e3dece2b05027a /src/encoding.rs | |
| parent | 4997c2a4e4856b49668a3d1257e967597c7dfb92 (diff) | |
add a loop that reads a character of user input
(right now it exits after the first time, doing nothing) Force-Push: yes Change-Id: I89f8d3d298e6a42e373e536121e6b434e30ef66f
Diffstat (limited to 'src/encoding.rs')
| -rw-r--r-- | src/encoding.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/encoding.rs b/src/encoding.rs new file mode 100644 index 0000000..7d5326e --- /dev/null +++ b/src/encoding.rs @@ -0,0 +1,28 @@ +#![forbid(unsafe_code)] + + +#[derive(Clone, Copy, Debug)] +pub enum UTF8ByteType { + Single, + Introducer(u8), + Continuation, + Invalid, +} + + +pub fn get_utf8_byte_type(b: u8) -> UTF8ByteType { + if b & 0x80 == 0 { + UTF8ByteType::Single + } else if b & 0xC0 == 0x80 { + UTF8ByteType::Continuation + } else if b & 0xE0 == 0xC0 { + UTF8ByteType::Introducer(2) + } else if b & 0xF0 == 0xE0 { + UTF8ByteType::Introducer(3) + } else if b & 0xF8 == 0xF0 { + UTF8ByteType::Introducer(4) + } else { + UTF8ByteType::Invalid + } +} + |