summary refs log tree commit diff
path: root/src/encoding.rs
blob: 7d5326e2d276d8c44c8365f9e8e4793fc0d63daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
  }
}