Skip to main content

is_safe_byte_range

Function is_safe_byte_range 

Source
pub fn is_safe_byte_range(start: u32) -> bool
Expand description

Checks whether a ByteRange dictionary with the given start_codepoint is safe for encoding all 256 possible byte values (0-255).

A range is considered unsafe if any mapped codepoint falls in:

  • U+0000 (NUL) – causes CString/git failures
  • U+0001..=U+001F (C0 control characters) – non-printable, break terminals/parsers
  • U+007F (DEL) – non-printable control character
  • U+0080..=U+009F (C1 control characters) – non-printable, break terminals/parsers
  • U+D800..=U+DFFF (surrogates) – invalid in UTF-8, char::from_u32 returns None

A safe start_codepoint must satisfy:

  • start >= 0x00A0 (skips NUL, C0 controls, DEL, and C1 controls)
  • start + 255 < 0xD800 OR start > 0xDFFF (avoids surrogate gap)
  • start + 255 <= 0x10FFFF (stays within Unicode)