1 //! character specific parsers and combinators
2 //!
3 //! functions recognizing specific characters
4 
5 #[macro_use]
6 mod macros;
7 
8 pub mod streaming;
9 pub mod complete;
10 
11 /// Tests if byte is ASCII alphabetic: A-Z, a-z
12 ///
13 /// # Example
14 ///
15 /// ```
16 /// # use nom::character::is_alphabetic;
17 /// assert_eq!(is_alphabetic(b'9'), false);
18 /// assert_eq!(is_alphabetic(b'a'), true);
19 /// ```
20 #[inline]
is_alphabetic(chr: u8) -> bool21 pub fn is_alphabetic(chr: u8) -> bool {
22   (chr >= 0x41 && chr <= 0x5A) || (chr >= 0x61 && chr <= 0x7A)
23 }
24 
25 /// Tests if byte is ASCII digit: 0-9
26 ///
27 /// # Example
28 ///
29 /// ```
30 /// # use nom::character::is_digit;
31 /// assert_eq!(is_digit(b'a'), false);
32 /// assert_eq!(is_digit(b'9'), true);
33 /// ```
34 #[inline]
is_digit(chr: u8) -> bool35 pub fn is_digit(chr: u8) -> bool {
36   chr >= 0x30 && chr <= 0x39
37 }
38 
39 /// Tests if byte is ASCII hex digit: 0-9, A-F, a-f
40 ///
41 /// # Example
42 ///
43 /// ```
44 /// # use nom::character::is_hex_digit;
45 /// assert_eq!(is_hex_digit(b'a'), true);
46 /// assert_eq!(is_hex_digit(b'9'), true);
47 /// assert_eq!(is_hex_digit(b'A'), true);
48 /// assert_eq!(is_hex_digit(b'x'), false);
49 /// ```
50 #[inline]
is_hex_digit(chr: u8) -> bool51 pub fn is_hex_digit(chr: u8) -> bool {
52   (chr >= 0x30 && chr <= 0x39) || (chr >= 0x41 && chr <= 0x46) || (chr >= 0x61 && chr <= 0x66)
53 }
54 
55 /// Tests if byte is ASCII octal digit: 0-7
56 ///
57 /// # Example
58 ///
59 /// ```
60 /// # use nom::character::is_oct_digit;
61 /// assert_eq!(is_oct_digit(b'a'), false);
62 /// assert_eq!(is_oct_digit(b'9'), false);
63 /// assert_eq!(is_oct_digit(b'6'), true);
64 /// ```
65 #[inline]
is_oct_digit(chr: u8) -> bool66 pub fn is_oct_digit(chr: u8) -> bool {
67   chr >= 0x30 && chr <= 0x37
68 }
69 
70 /// Tests if byte is ASCII alphanumeric: A-Z, a-z, 0-9
71 ///
72 /// # Example
73 ///
74 /// ```
75 /// # use nom::character::is_alphanumeric;
76 /// assert_eq!(is_alphanumeric(b'-'), false);
77 /// assert_eq!(is_alphanumeric(b'a'), true);
78 /// assert_eq!(is_alphanumeric(b'9'), true);
79 /// assert_eq!(is_alphanumeric(b'A'), true);
80 /// ```
81 #[inline]
is_alphanumeric(chr: u8) -> bool82 pub fn is_alphanumeric(chr: u8) -> bool {
83   is_alphabetic(chr) || is_digit(chr)
84 }
85 
86 /// Tests if byte is ASCII space or tab
87 ///
88 /// # Example
89 ///
90 /// ```
91 /// # use nom::character::is_space;
92 /// assert_eq!(is_space(b'\n'), false);
93 /// assert_eq!(is_space(b'\r'), false);
94 /// assert_eq!(is_space(b' '), true);
95 /// assert_eq!(is_space(b'\t'), true);
96 /// ```
97 #[inline]
is_space(chr: u8) -> bool98 pub fn is_space(chr: u8) -> bool {
99   chr == b' ' || chr == b'\t'
100 }
101 
102