diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index ae77813..4da5515 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -211,38 +211,55 @@ impl> Iterator for Scanner { } } +/// Check whether the character is nil (`\0`). #[inline] fn is_z(c: char) -> bool { c == '\0' } + +/// Check whether the character is a line break (`\r` or `\n`). #[inline] fn is_break(c: char) -> bool { c == '\n' || c == '\r' } + +/// Check whether the character is nil or a line break (`\0`, `\r`, `\n`). #[inline] fn is_breakz(c: char) -> bool { is_break(c) || is_z(c) } + +/// Check whether the character is a whitespace (` ` or `\t`). #[inline] fn is_blank(c: char) -> bool { c == ' ' || c == '\t' } + +/// Check whether the character is nil or a whitespace (`\0`, ` `, `\t`). #[inline] fn is_blankz(c: char) -> bool { is_blank(c) || is_breakz(c) } + +/// Check whether the character is an ascii digit. #[inline] fn is_digit(c: char) -> bool { c.is_ascii_digit() } + +/// Check whether the character is a digit, letter, `_` or `-`. #[inline] fn is_alpha(c: char) -> bool { matches!(c, '0'..='9' | 'a'..='z' | 'A'..='Z' | '_' | '-') } + +/// Check whether the character is a hexadecimal character (case insensitive). #[inline] fn is_hex(c: char) -> bool { c.is_ascii_digit() || ('a'..='f').contains(&c) || ('A'..='F').contains(&c) } + +/// Convert the hexadecimal digit to an integer. #[inline] fn as_hex(c: char) -> u32 { match c { @@ -252,6 +269,8 @@ fn as_hex(c: char) -> u32 { _ => unreachable!(), } } + +/// Check whether the character is a YAML flow character (one of `,[]{}`). #[inline] fn is_flow(c: char) -> bool { matches!(c, ',' | '[' | ']' | '{' | '}')