From 10327d770eb19764d1e272d2f32a4f0e3edd9062 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 27 Mar 2026 03:42:32 -0700 Subject: 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 --- src/encoding.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/encoding.rs (limited to 'src/encoding.rs') 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 + } +} + -- cgit 1.4.1