aboutsummaryrefslogtreecommitdiff
path: root/src/character/mod.rs
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2020-04-07 14:24:02 -0700
committerChih-Hung Hsieh <chh@google.com>2020-04-07 14:27:38 -0700
commit39f7476eb664742a304ee7844307e1260d5d2a12 (patch)
tree11e5f3dbaeb789d18fd43487966f9459e2c49aa8 /src/character/mod.rs
parent36f37ff070b0f672a1cf4baa50ff8fc5c5452bc6 (diff)
downloadnom-39f7476eb664742a304ee7844307e1260d5d2a12.tar.gz
Import 'nom' package version 5.1.1platform-tools-30.0.0
* Add OWNERS * No Android.bp yet Bug: 152884384 Test: make Change-Id: I938710bbf1db778e580460b988613f890f434256
Diffstat (limited to 'src/character/mod.rs')
-rw-r--r--src/character/mod.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/character/mod.rs b/src/character/mod.rs
new file mode 100644
index 0000000..3f0899a
--- /dev/null
+++ b/src/character/mod.rs
@@ -0,0 +1,101 @@
+//! character specific parsers and combinators
+//!
+//! functions recognizing specific characters
+
+#[macro_use]
+mod macros;
+
+pub mod streaming;
+pub mod complete;
+
+/// Tests if byte is ASCII alphabetic: A-Z, a-z
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_alphabetic;
+/// assert_eq!(is_alphabetic(b'9'), false);
+/// assert_eq!(is_alphabetic(b'a'), true);
+/// ```
+#[inline]
+pub fn is_alphabetic(chr: u8) -> bool {
+ (chr >= 0x41 && chr <= 0x5A) || (chr >= 0x61 && chr <= 0x7A)
+}
+
+/// Tests if byte is ASCII digit: 0-9
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_digit;
+/// assert_eq!(is_digit(b'a'), false);
+/// assert_eq!(is_digit(b'9'), true);
+/// ```
+#[inline]
+pub fn is_digit(chr: u8) -> bool {
+ chr >= 0x30 && chr <= 0x39
+}
+
+/// Tests if byte is ASCII hex digit: 0-9, A-F, a-f
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_hex_digit;
+/// assert_eq!(is_hex_digit(b'a'), true);
+/// assert_eq!(is_hex_digit(b'9'), true);
+/// assert_eq!(is_hex_digit(b'A'), true);
+/// assert_eq!(is_hex_digit(b'x'), false);
+/// ```
+#[inline]
+pub fn is_hex_digit(chr: u8) -> bool {
+ (chr >= 0x30 && chr <= 0x39) || (chr >= 0x41 && chr <= 0x46) || (chr >= 0x61 && chr <= 0x66)
+}
+
+/// Tests if byte is ASCII octal digit: 0-7
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_oct_digit;
+/// assert_eq!(is_oct_digit(b'a'), false);
+/// assert_eq!(is_oct_digit(b'9'), false);
+/// assert_eq!(is_oct_digit(b'6'), true);
+/// ```
+#[inline]
+pub fn is_oct_digit(chr: u8) -> bool {
+ chr >= 0x30 && chr <= 0x37
+}
+
+/// Tests if byte is ASCII alphanumeric: A-Z, a-z, 0-9
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_alphanumeric;
+/// assert_eq!(is_alphanumeric(b'-'), false);
+/// assert_eq!(is_alphanumeric(b'a'), true);
+/// assert_eq!(is_alphanumeric(b'9'), true);
+/// assert_eq!(is_alphanumeric(b'A'), true);
+/// ```
+#[inline]
+pub fn is_alphanumeric(chr: u8) -> bool {
+ is_alphabetic(chr) || is_digit(chr)
+}
+
+/// Tests if byte is ASCII space or tab
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_space;
+/// assert_eq!(is_space(b'\n'), false);
+/// assert_eq!(is_space(b'\r'), false);
+/// assert_eq!(is_space(b' '), true);
+/// assert_eq!(is_space(b'\t'), true);
+/// ```
+#[inline]
+pub fn is_space(chr: u8) -> bool {
+ chr == b' ' || chr == b'\t'
+}
+