ixdtf/parsers/
grammar.rs

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! ISO8601 specific grammar checks.

/// Checks if char is a `AKeyLeadingChar`.
#[inline]
pub(crate) const fn is_a_key_leading_char(ch: char) -> bool {
    ch.is_ascii_lowercase() || ch == '_'
}

/// Checks if char is an `AKeyChar`.
#[inline]
pub(crate) const fn is_a_key_char(ch: char) -> bool {
    is_a_key_leading_char(ch) || ch.is_ascii_digit() || ch == '-'
}

/// Checks if char is an `AnnotationValueComponent`.
pub(crate) const fn is_annotation_value_component(ch: char) -> bool {
    ch.is_ascii_digit() || ch.is_ascii_alphabetic()
}

/// Checks if char is a `TZLeadingChar`.
#[inline]
pub(crate) const fn is_tz_leading_char(ch: char) -> bool {
    ch.is_ascii_alphabetic() || ch == '_' || ch == '.'
}

/// Checks if char is a `TZChar`.
#[inline]
pub(crate) const fn is_tz_char(ch: char) -> bool {
    is_tz_leading_char(ch) || ch.is_ascii_digit() || ch == '-' || ch == '+'
}

/// Checks if char is a `TimeZoneIANAName` Separator.
#[inline]
pub(crate) const fn is_tz_name_separator(ch: char) -> bool {
    ch == '/'
}

/// Checks if char is an ascii sign.
#[inline]
pub(crate) const fn is_ascii_sign(ch: char) -> bool {
    ch == '+' || ch == '-'
}

/// Checks if char is an ascii sign or U+2212
#[inline]
pub(crate) const fn is_sign(ch: char) -> bool {
    is_ascii_sign(ch) || ch == '\u{2212}'
}

/// Checks if char is a `TimeSeparator`.
#[inline]
pub(crate) const fn is_time_separator(ch: char) -> bool {
    ch == ':'
}

/// Checks if char is a `TimeDesignator`.
#[inline]
pub(crate) const fn is_time_designator(ch: char) -> bool {
    ch == 'T' || ch == 't'
}

#[inline]
/// Checks if char is a space.
pub(crate) const fn is_space(ch: char) -> bool {
    ch == ' '
}

/// Checks if char is a `DateTimeSeparator`.
#[inline]
pub(crate) const fn is_date_time_separator(ch: char) -> bool {
    is_time_designator(ch) || is_space(ch)
}

/// Checks if char is a `UtcDesignator`.
#[inline]
pub(crate) const fn is_utc_designator(ch: char) -> bool {
    ch == 'Z' || ch == 'z'
}

/// Checks if char is a `DurationDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_duration_designator(ch: char) -> bool {
    ch == 'P' || ch == 'p'
}

/// Checks if char is a `YearDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_year_designator(ch: char) -> bool {
    ch == 'Y' || ch == 'y'
}

/// Checks if char is a `MonthsDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_month_designator(ch: char) -> bool {
    ch == 'M' || ch == 'm'
}

/// Checks if char is a `WeekDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_week_designator(ch: char) -> bool {
    ch == 'W' || ch == 'w'
}

/// Checks if char is a `DayDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_day_designator(ch: char) -> bool {
    ch == 'D' || ch == 'd'
}

/// checks if char is a `DayDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_hour_designator(ch: char) -> bool {
    ch == 'H' || ch == 'h'
}

/// Checks if char is a `MinuteDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_minute_designator(ch: char) -> bool {
    is_month_designator(ch)
}

/// checks if char is a `SecondDesignator`.
#[inline]
#[cfg(feature = "duration")]
pub(crate) const fn is_second_designator(ch: char) -> bool {
    ch == 'S' || ch == 's'
}

/// Checks if char is a `DecimalSeparator`.
#[inline]
pub(crate) const fn is_decimal_separator(ch: char) -> bool {
    ch == '.' || ch == ','
}

/// Checks if char is an `AnnotationOpen`.
#[inline]
pub(crate) const fn is_annotation_open(ch: char) -> bool {
    ch == '['
}

/// Checks if char is an `AnnotationClose`.
#[inline]
pub(crate) const fn is_annotation_close(ch: char) -> bool {
    ch == ']'
}

/// Checks if char is an `CriticalFlag`.
#[inline]
pub(crate) const fn is_critical_flag(ch: char) -> bool {
    ch == '!'
}

/// Checks if char is the `AnnotationKeyValueSeparator`.
#[inline]
pub(crate) const fn is_annotation_key_value_separator(ch: char) -> bool {
    ch == '='
}

/// Checks if char is a hyphen. Hyphens are used as a Date separator
/// and as a `AttributeValueComponent` separator.
#[inline]
pub(crate) const fn is_hyphen(ch: char) -> bool {
    ch == '-'
}