summaryrefslogtreecommitdiff
path: root/grammar/src/abnf/boolean_fns.rs
blob: 08f317c2fd30055699c5d69ef303dea67b141386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! This file collects some functions that return a boolean value from
//! a character.

pub(super) fn is_wsp(c: char) -> bool {
    c == ' ' || c == '\t'
}

pub(crate) fn is_v_char(c: char) -> bool {
    ('!'..='~').contains(&c)
}

pub(super) fn is_wsp_or_v_char(c: char) -> bool {
    is_wsp(c) || is_v_char(c)
}

pub(super) fn is_not_newline(c: char) -> bool {
    c != '\n' && c != '\r'
}

pub(super) fn is_alpha(c: char) -> bool {
    c.is_ascii_alphabetic()
}

pub(super) fn is_decimal_digit(c: char) -> bool {
    c.is_ascii_digit()
}

pub(super) fn is_binary_digit(c: char) -> bool {
    c == '0' || c == '1'
}

pub(super) fn is_hexadecimal_digit(c: char) -> bool {
    is_decimal_digit(c) || ('A'..='F').contains(&c) || ('a'..='f').contains(&c)
}

pub(super) fn is_alpha_or_digit_or_hyphen(c: char) -> bool {
    is_alpha(c) || is_decimal_digit(c) || c == '-'
}

pub(super) fn is_char_value(c: char) -> bool {
    (' '..='~').contains(&c) && c != '"'
}