2019-05-13 09:41:24 +00:00
|
|
|
//! Utilities for validating string and char literals and turning them into
|
2019-04-25 08:48:25 +00:00
|
|
|
//! values they represent.
|
|
|
|
|
|
|
|
use std::ops::Range;
|
|
|
|
use std::str::Chars;
|
|
|
|
|
2019-08-01 00:19:11 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2021-07-30 14:09:33 +00:00
|
|
|
/// Errors and warnings that can occur during string unescaping.
|
2019-04-25 08:48:25 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2019-07-21 13:46:11 +00:00
|
|
|
pub enum EscapeError {
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Expected 1 char, but 0 were found.
|
2019-04-25 08:48:25 +00:00
|
|
|
ZeroChars,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Expected 1 char, but more than 1 were found.
|
2019-04-25 08:48:25 +00:00
|
|
|
MoreThanOneChar,
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Escaped '\' character without continuation.
|
2019-04-25 08:48:25 +00:00
|
|
|
LoneSlash,
|
2020-03-06 11:13:55 +00:00
|
|
|
/// Invalid escape character (e.g. '\z').
|
2019-04-25 08:48:25 +00:00
|
|
|
InvalidEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Raw '\r' encountered.
|
2019-04-25 08:48:25 +00:00
|
|
|
BareCarriageReturn,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Raw '\r' encountered in raw string.
|
2019-06-10 15:32:15 +00:00
|
|
|
BareCarriageReturnInRawString,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Unescaped character that was expected to be escaped (e.g. raw '\t').
|
2019-04-25 08:48:25 +00:00
|
|
|
EscapeOnlyChar,
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Numeric character escape is too short (e.g. '\x1').
|
2019-04-25 08:48:25 +00:00
|
|
|
TooShortHexEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Invalid character in numeric escape (e.g. '\xz')
|
2019-04-25 08:48:25 +00:00
|
|
|
InvalidCharInHexEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Character code in numeric escape is non-ascii (e.g. '\xFF').
|
2019-04-25 08:48:25 +00:00
|
|
|
OutOfRangeHexEscape,
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
/// '\u' not followed by '{'.
|
2019-04-25 08:48:25 +00:00
|
|
|
NoBraceInUnicodeEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Non-hexadecimal value in '\u{..}'.
|
2019-04-25 08:48:25 +00:00
|
|
|
InvalidCharInUnicodeEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// '\u{}'
|
2019-04-25 08:48:25 +00:00
|
|
|
EmptyUnicodeEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// No closing brace in '\u{..}', e.g. '\u{12'.
|
2019-04-25 08:48:25 +00:00
|
|
|
UnclosedUnicodeEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// '\u{_12}'
|
2019-04-25 08:48:25 +00:00
|
|
|
LeadingUnderscoreUnicodeEscape,
|
2020-03-06 11:13:55 +00:00
|
|
|
/// More than 6 characters in '\u{..}', e.g. '\u{10FFFF_FF}'
|
2019-04-25 08:48:25 +00:00
|
|
|
OverlongUnicodeEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Invalid in-bound unicode character code, e.g. '\u{DFFF}'.
|
2019-04-25 08:48:25 +00:00
|
|
|
LoneSurrogateUnicodeEscape,
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Out of bounds unicode character code, e.g. '\u{FFFFFF}'.
|
2019-04-25 08:48:25 +00:00
|
|
|
OutOfRangeUnicodeEscape,
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Unicode escape code in byte literal.
|
2019-04-25 08:48:25 +00:00
|
|
|
UnicodeEscapeInByte,
|
2022-11-03 04:17:37 +00:00
|
|
|
/// Non-ascii character in byte literal, byte string literal, or raw byte string literal.
|
2019-04-25 08:48:25 +00:00
|
|
|
NonAsciiCharInByte,
|
2021-07-30 14:09:33 +00:00
|
|
|
|
|
|
|
/// After a line ending with '\', the next line contains whitespace
|
|
|
|
/// characters that are not skipped.
|
|
|
|
UnskippedWhitespaceWarning,
|
2021-07-31 18:35:37 +00:00
|
|
|
|
|
|
|
/// After a line ending with '\', multiple lines are skipped.
|
|
|
|
MultipleSkippedLinesWarning,
|
2021-07-30 14:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EscapeError {
|
|
|
|
/// Returns true for actual errors, as opposed to warnings.
|
|
|
|
pub fn is_fatal(&self) -> bool {
|
2021-11-06 00:31:32 +00:00
|
|
|
!matches!(
|
|
|
|
self,
|
|
|
|
EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning
|
|
|
|
)
|
2021-07-30 14:09:33 +00:00
|
|
|
}
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 07:42:30 +00:00
|
|
|
/// Takes a contents of a literal (without quotes) and produces a
|
|
|
|
/// sequence of escaped characters or errors.
|
|
|
|
/// Values are returned through invoking of the provided callback.
|
2022-11-03 00:31:07 +00:00
|
|
|
pub fn unescape_literal<F>(src: &str, mode: Mode, callback: &mut F)
|
2020-05-13 07:42:30 +00:00
|
|
|
where
|
|
|
|
F: FnMut(Range<usize>, Result<char, EscapeError>),
|
|
|
|
{
|
|
|
|
match mode {
|
|
|
|
Mode::Char | Mode::Byte => {
|
2022-11-03 00:31:07 +00:00
|
|
|
let mut chars = src.chars();
|
2022-11-04 02:52:44 +00:00
|
|
|
let res = unescape_char_or_byte(&mut chars, mode == Mode::Byte);
|
|
|
|
callback(0..(src.len() - chars.as_str().len()), res);
|
2020-05-13 07:42:30 +00:00
|
|
|
}
|
2022-11-03 02:35:49 +00:00
|
|
|
Mode::Str | Mode::ByteStr => unescape_str_or_byte_str(src, mode == Mode::ByteStr, callback),
|
|
|
|
Mode::RawStr | Mode::RawByteStr => {
|
|
|
|
unescape_raw_str_or_raw_byte_str(src, mode == Mode::RawByteStr, callback)
|
|
|
|
}
|
2020-05-13 07:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-25 08:48:25 +00:00
|
|
|
/// Takes a contents of a char literal (without quotes), and returns an
|
2022-11-08 04:59:19 +00:00
|
|
|
/// unescaped char or an error.
|
|
|
|
pub fn unescape_char(src: &str) -> Result<char, EscapeError> {
|
|
|
|
unescape_char_or_byte(&mut src.chars(), false)
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
/// Takes a contents of a byte literal (without quotes), and returns an
|
|
|
|
/// unescaped byte or an error.
|
2022-11-08 04:59:19 +00:00
|
|
|
pub fn unescape_byte(src: &str) -> Result<u8, EscapeError> {
|
|
|
|
unescape_char_or_byte(&mut src.chars(), true).map(byte_from_char)
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
/// What kind of literal do we parse.
|
2022-09-27 06:32:22 +00:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2019-07-21 13:46:11 +00:00
|
|
|
pub enum Mode {
|
2019-04-25 08:48:25 +00:00
|
|
|
Char,
|
|
|
|
Str,
|
|
|
|
Byte,
|
|
|
|
ByteStr,
|
2020-05-13 07:42:30 +00:00
|
|
|
RawStr,
|
|
|
|
RawByteStr,
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Mode {
|
2022-09-27 06:32:22 +00:00
|
|
|
pub fn in_double_quotes(self) -> bool {
|
2019-04-25 08:48:25 +00:00
|
|
|
match self {
|
2022-09-27 06:32:22 +00:00
|
|
|
Mode::Str | Mode::ByteStr | Mode::RawStr | Mode::RawByteStr => true,
|
|
|
|
Mode::Char | Mode::Byte => false,
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 02:35:49 +00:00
|
|
|
pub fn is_byte(self) -> bool {
|
2019-04-25 08:48:25 +00:00
|
|
|
match self {
|
2020-05-13 07:42:30 +00:00
|
|
|
Mode::Byte | Mode::ByteStr | Mode::RawByteStr => true,
|
|
|
|
Mode::Char | Mode::Str | Mode::RawStr => false,
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 02:35:49 +00:00
|
|
|
fn scan_escape(chars: &mut Chars<'_>, is_byte: bool) -> Result<char, EscapeError> {
|
2022-02-24 05:10:36 +00:00
|
|
|
// Previous character was '\\', unescape what follows.
|
2022-11-03 00:31:07 +00:00
|
|
|
let res = match chars.next().ok_or(EscapeError::LoneSlash)? {
|
2019-04-25 08:48:25 +00:00
|
|
|
'"' => '"',
|
|
|
|
'n' => '\n',
|
|
|
|
'r' => '\r',
|
|
|
|
't' => '\t',
|
|
|
|
'\\' => '\\',
|
|
|
|
'\'' => '\'',
|
|
|
|
'0' => '\0',
|
|
|
|
|
|
|
|
'x' => {
|
2019-10-26 16:12:58 +00:00
|
|
|
// Parse hexadecimal character code.
|
|
|
|
|
2019-04-25 08:48:25 +00:00
|
|
|
let hi = chars.next().ok_or(EscapeError::TooShortHexEscape)?;
|
|
|
|
let hi = hi.to_digit(16).ok_or(EscapeError::InvalidCharInHexEscape)?;
|
|
|
|
|
|
|
|
let lo = chars.next().ok_or(EscapeError::TooShortHexEscape)?;
|
|
|
|
let lo = lo.to_digit(16).ok_or(EscapeError::InvalidCharInHexEscape)?;
|
|
|
|
|
|
|
|
let value = hi * 16 + lo;
|
|
|
|
|
2022-09-27 05:25:34 +00:00
|
|
|
// For a non-byte literal verify that it is within ASCII range.
|
2022-11-03 02:35:49 +00:00
|
|
|
if !is_byte && !is_ascii(value) {
|
2019-04-25 08:48:25 +00:00
|
|
|
return Err(EscapeError::OutOfRangeHexEscape);
|
|
|
|
}
|
|
|
|
let value = value as u8;
|
|
|
|
|
|
|
|
value as char
|
|
|
|
}
|
|
|
|
|
|
|
|
'u' => {
|
2019-10-26 16:12:58 +00:00
|
|
|
// We've parsed '\u', now we have to parse '{..}'.
|
|
|
|
|
2019-04-25 08:48:25 +00:00
|
|
|
if chars.next() != Some('{') {
|
|
|
|
return Err(EscapeError::NoBraceInUnicodeEscape);
|
|
|
|
}
|
|
|
|
|
2020-12-18 13:13:25 +00:00
|
|
|
// First character must be a hexadecimal digit.
|
2019-04-25 08:48:25 +00:00
|
|
|
let mut n_digits = 1;
|
|
|
|
let mut value: u32 = match chars.next().ok_or(EscapeError::UnclosedUnicodeEscape)? {
|
|
|
|
'_' => return Err(EscapeError::LeadingUnderscoreUnicodeEscape),
|
|
|
|
'}' => return Err(EscapeError::EmptyUnicodeEscape),
|
|
|
|
c => c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?,
|
|
|
|
};
|
|
|
|
|
2019-10-26 16:12:58 +00:00
|
|
|
// First character is valid, now parse the rest of the number
|
|
|
|
// and closing brace.
|
2019-04-25 08:48:25 +00:00
|
|
|
loop {
|
|
|
|
match chars.next() {
|
|
|
|
None => return Err(EscapeError::UnclosedUnicodeEscape),
|
|
|
|
Some('_') => continue,
|
|
|
|
Some('}') => {
|
|
|
|
if n_digits > 6 {
|
|
|
|
return Err(EscapeError::OverlongUnicodeEscape);
|
|
|
|
}
|
2019-10-26 16:12:58 +00:00
|
|
|
|
|
|
|
// Incorrect syntax has higher priority for error reporting
|
|
|
|
// than unallowed value for a literal.
|
2022-11-03 02:35:49 +00:00
|
|
|
if is_byte {
|
2019-04-25 08:48:25 +00:00
|
|
|
return Err(EscapeError::UnicodeEscapeInByte);
|
|
|
|
}
|
|
|
|
|
|
|
|
break std::char::from_u32(value).ok_or_else(|| {
|
|
|
|
if value > 0x10FFFF {
|
|
|
|
EscapeError::OutOfRangeUnicodeEscape
|
|
|
|
} else {
|
|
|
|
EscapeError::LoneSurrogateUnicodeEscape
|
|
|
|
}
|
|
|
|
})?;
|
|
|
|
}
|
|
|
|
Some(c) => {
|
2022-12-12 18:49:53 +00:00
|
|
|
let digit: u32 =
|
2019-04-25 08:48:25 +00:00
|
|
|
c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?;
|
|
|
|
n_digits += 1;
|
|
|
|
if n_digits > 6 {
|
2022-06-28 14:29:09 +00:00
|
|
|
// Stop updating value since we're sure that it's incorrect already.
|
2019-04-25 08:48:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
value = value * 16 + digit;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => return Err(EscapeError::InvalidEscape),
|
|
|
|
};
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
2022-02-24 05:10:36 +00:00
|
|
|
#[inline]
|
2022-11-03 02:35:49 +00:00
|
|
|
fn ascii_check(c: char, is_byte: bool) -> Result<char, EscapeError> {
|
|
|
|
if is_byte && !c.is_ascii() {
|
2022-02-24 05:10:36 +00:00
|
|
|
// Byte literal can't be a non-ascii character.
|
|
|
|
Err(EscapeError::NonAsciiCharInByte)
|
|
|
|
} else {
|
2022-11-03 00:31:07 +00:00
|
|
|
Ok(c)
|
2022-02-24 05:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 02:35:49 +00:00
|
|
|
fn unescape_char_or_byte(chars: &mut Chars<'_>, is_byte: bool) -> Result<char, EscapeError> {
|
2022-11-03 00:31:07 +00:00
|
|
|
let c = chars.next().ok_or(EscapeError::ZeroChars)?;
|
|
|
|
let res = match c {
|
2022-11-03 02:35:49 +00:00
|
|
|
'\\' => scan_escape(chars, is_byte),
|
2022-02-24 05:10:36 +00:00
|
|
|
'\n' | '\t' | '\'' => Err(EscapeError::EscapeOnlyChar),
|
|
|
|
'\r' => Err(EscapeError::BareCarriageReturn),
|
2022-11-03 02:35:49 +00:00
|
|
|
_ => ascii_check(c, is_byte),
|
2022-02-24 05:10:36 +00:00
|
|
|
}?;
|
2019-04-25 08:48:25 +00:00
|
|
|
if chars.next().is_some() {
|
|
|
|
return Err(EscapeError::MoreThanOneChar);
|
|
|
|
}
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Takes a contents of a string literal (without quotes) and produces a
|
|
|
|
/// sequence of escaped characters or errors.
|
2022-11-03 02:35:49 +00:00
|
|
|
fn unescape_str_or_byte_str<F>(src: &str, is_byte: bool, callback: &mut F)
|
2019-04-25 08:48:25 +00:00
|
|
|
where
|
|
|
|
F: FnMut(Range<usize>, Result<char, EscapeError>),
|
|
|
|
{
|
|
|
|
let mut chars = src.chars();
|
|
|
|
|
2022-11-03 01:15:55 +00:00
|
|
|
// The `start` and `end` computation here is complicated because
|
|
|
|
// `skip_ascii_whitespace` makes us to skip over chars without counting
|
|
|
|
// them in the range computation.
|
|
|
|
while let Some(c) = chars.next() {
|
|
|
|
let start = src.len() - chars.as_str().len() - c.len_utf8();
|
2022-11-04 02:52:44 +00:00
|
|
|
let res = match c {
|
2019-04-25 08:48:25 +00:00
|
|
|
'\\' => {
|
2022-11-03 00:31:07 +00:00
|
|
|
match chars.clone().next() {
|
2019-08-14 13:38:40 +00:00
|
|
|
Some('\n') => {
|
2019-10-26 16:12:58 +00:00
|
|
|
// Rust language specification requires us to skip whitespaces
|
|
|
|
// if unescaped '\' character is followed by '\n'.
|
|
|
|
// For details see [Rust language reference]
|
|
|
|
// (https://doc.rust-lang.org/reference/tokens.html#string-literals).
|
2021-07-30 14:09:33 +00:00
|
|
|
skip_ascii_whitespace(&mut chars, start, callback);
|
2019-04-25 08:48:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-11-03 02:35:49 +00:00
|
|
|
_ => scan_escape(&mut chars, is_byte),
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
'\n' => Ok('\n'),
|
|
|
|
'\t' => Ok('\t'),
|
2022-02-24 05:10:36 +00:00
|
|
|
'"' => Err(EscapeError::EscapeOnlyChar),
|
|
|
|
'\r' => Err(EscapeError::BareCarriageReturn),
|
2022-11-03 02:35:49 +00:00
|
|
|
_ => ascii_check(c, is_byte),
|
2019-04-25 08:48:25 +00:00
|
|
|
};
|
2022-11-03 01:15:55 +00:00
|
|
|
let end = src.len() - chars.as_str().len();
|
2022-11-04 02:52:44 +00:00
|
|
|
callback(start..end, res);
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 14:09:33 +00:00
|
|
|
fn skip_ascii_whitespace<F>(chars: &mut Chars<'_>, start: usize, callback: &mut F)
|
|
|
|
where
|
|
|
|
F: FnMut(Range<usize>, Result<char, EscapeError>),
|
|
|
|
{
|
2021-08-11 11:57:28 +00:00
|
|
|
let tail = chars.as_str();
|
|
|
|
let first_non_space = tail
|
2019-04-25 08:48:25 +00:00
|
|
|
.bytes()
|
|
|
|
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
|
2021-08-11 11:57:28 +00:00
|
|
|
.unwrap_or(tail.len());
|
|
|
|
if tail[1..first_non_space].contains('\n') {
|
2021-07-31 18:35:37 +00:00
|
|
|
// The +1 accounts for the escaping slash.
|
|
|
|
let end = start + first_non_space + 1;
|
|
|
|
callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning));
|
|
|
|
}
|
2021-08-11 11:57:28 +00:00
|
|
|
let tail = &tail[first_non_space..];
|
2021-10-15 09:24:20 +00:00
|
|
|
if let Some(c) = tail.chars().nth(0) {
|
2021-07-30 14:09:33 +00:00
|
|
|
if c.is_whitespace() {
|
2023-03-09 14:42:06 +00:00
|
|
|
// For error reporting, we would like the span to contain the character that was not
|
|
|
|
// skipped. The +1 is necessary to account for the leading \ that started the escape.
|
|
|
|
let end = start + first_non_space + c.len_utf8() + 1;
|
2021-07-30 14:09:33 +00:00
|
|
|
callback(start..end, Err(EscapeError::UnskippedWhitespaceWarning));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*chars = tail.chars();
|
2019-04-25 08:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 12:43:31 +00:00
|
|
|
/// Takes a contents of a string literal (without quotes) and produces a
|
|
|
|
/// sequence of characters or errors.
|
|
|
|
/// NOTE: Raw strings do not perform any explicit character escaping, here we
|
2022-11-03 05:26:27 +00:00
|
|
|
/// only produce errors on bare CR.
|
2022-11-03 02:35:49 +00:00
|
|
|
fn unescape_raw_str_or_raw_byte_str<F>(src: &str, is_byte: bool, callback: &mut F)
|
2019-06-09 12:43:31 +00:00
|
|
|
where
|
|
|
|
F: FnMut(Range<usize>, Result<char, EscapeError>),
|
|
|
|
{
|
2022-11-03 00:31:07 +00:00
|
|
|
let mut chars = src.chars();
|
2019-06-09 13:44:18 +00:00
|
|
|
|
2022-11-03 01:15:55 +00:00
|
|
|
// The `start` and `end` computation here matches the one in
|
|
|
|
// `unescape_str_or_byte_str` for consistency, even though this function
|
|
|
|
// doesn't have to worry about skipping any chars.
|
|
|
|
while let Some(c) = chars.next() {
|
|
|
|
let start = src.len() - chars.as_str().len() - c.len_utf8();
|
2022-11-04 02:52:44 +00:00
|
|
|
let res = match c {
|
2019-08-14 13:38:40 +00:00
|
|
|
'\r' => Err(EscapeError::BareCarriageReturnInRawString),
|
2022-11-03 04:17:37 +00:00
|
|
|
_ => ascii_check(c, is_byte),
|
2019-06-09 12:43:31 +00:00
|
|
|
};
|
2022-11-03 01:15:55 +00:00
|
|
|
let end = src.len() - chars.as_str().len();
|
2022-11-04 02:52:44 +00:00
|
|
|
callback(start..end, res);
|
2019-06-09 12:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 00:09:23 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn byte_from_char(c: char) -> u8 {
|
2019-04-25 08:48:25 +00:00
|
|
|
let res = c as u32;
|
2022-09-27 06:32:22 +00:00
|
|
|
debug_assert!(res <= u8::MAX as u32, "guaranteed because of Mode::ByteStr");
|
2019-04-25 08:48:25 +00:00
|
|
|
res as u8
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_ascii(x: u32) -> bool {
|
|
|
|
x <= 0x7F
|
|
|
|
}
|