4 #ifndef LEXY_CODE_POINT_HPP_INCLUDED
5 #define LEXY_CODE_POINT_HPP_INCLUDED
11 #if LEXY_HAS_UNICODE_DATABASE
12 # define LEXY_UNICODE_CONSTEXPR constexpr
14 # define LEXY_UNICODE_CONSTEXPR
26 constexpr
auto value() const noexcept
36 constexpr
bool is_bmp() const noexcept
42 return _value <= 0x10
'FFFF;
45 constexpr bool is_control() const noexcept
47 return _value <= 0x1F || (0x7F <= _value && _value <= 0x9F);
49 constexpr bool is_surrogate() const noexcept
51 return 0xD800 <= _value && _value <= 0xDFFF;
53 constexpr bool is_private_use() const noexcept
55 return (0xE000 <= _value && _value <= 0xF8FF)
59 constexpr bool is_noncharacter() const noexcept
61 // Contiguous range of 32 non-characters.
62 if (0xFDD0 <= _value && _value <= 0xFDEF)
65 // Last two code points of every plane.
66 auto in_plane = _value & 0xFFFF;
67 return in_plane == 0xFFFE || in_plane == 0xFFFF;
70 constexpr bool is_scalar() const noexcept
72 return is_valid() && !is_surrogate();
75 //=== general category ===//
76 enum general_category_t
78 // NOLINTNEXTLINE: can't use parentheses here
79 #define LEXY_UNICODE_CATEGORY(Short, Long) Short, Long = Short
118 #undef LEXY_UNICODE_CATEGORY
128 return ((
cat == Cats) || ...);
132 return ((
cat == Cats) || ...);
145 #define LEXY_UNICODE_CATEGORY_GROUP(Name, Short, Long, ...) \
146 static constexpr _gc_group<__VA_ARGS__> Short{"code-point." Name}; \
147 static constexpr _gc_group<__VA_ARGS__> Long = Short
158 #undef LEXY_UNICODE_CATEGORY_GROUP
165 return lhs._value == rhs._value;
169 return lhs._value != rhs._value;
185 case lexy::code_point::Lu:
186 return "code-point.uppercase-letter";
187 case lexy::code_point::Ll:
188 return "code-point.lowercase-letter";
189 case lexy::code_point::Lt:
190 return "code-point.titlecase-letter";
191 case lexy::code_point::Lm:
192 return "code-point.modifier-letter";
193 case lexy::code_point::Lo:
194 return "code-point.other-letter";
196 case lexy::code_point::Mn:
197 return "code-point.nonspacing-mark";
198 case lexy::code_point::Mc:
199 return "code-point.combining-mark";
200 case lexy::code_point::Me:
201 return "code-point.enclosing-mark";
203 case lexy::code_point::Nd:
204 return "code-point.decimal-number";
205 case lexy::code_point::Nl:
206 return "code-point.letter-number";
207 case lexy::code_point::No:
208 return "code-point.other-number";
210 case lexy::code_point::Pc:
211 return "code-point.connector-punctuation";
212 case lexy::code_point::Pd:
213 return "code-point.dash-punctuation";
214 case lexy::code_point::Ps:
215 return "code-point.open-punctuation";
216 case lexy::code_point::Pe:
217 return "code-point.close-punctuation";
218 case lexy::code_point::Pi:
219 return "code-point.initial-quote-punctuation";
220 case lexy::code_point::Pf:
221 return "code-point.final-quote-punctuation";
222 case lexy::code_point::Po:
223 return "code-point.other-punctuation";
225 case lexy::code_point::Sm:
226 return "code-point.math-symbol";
227 case lexy::code_point::Sc:
228 return "code-point.currency-symbol";
229 case lexy::code_point::Sk:
230 return "code-point.modifier-symbol";
231 case lexy::code_point::So:
232 return "code-point.other-symbol";
234 case lexy::code_point::Zs:
235 return "code-point.space-separator";
236 case lexy::code_point::Zl:
237 return "code-point.line-separator";
238 case lexy::code_point::Zp:
239 return "code-point.paragraph-separator";
241 case lexy::code_point::Cc:
242 return "code-point.control";
243 case lexy::code_point::Cf:
244 return "code-point.format";
245 case lexy::code_point::Cs:
246 return "code-point.surrogate";
247 case lexy::code_point::Co:
248 return "code-point.private-use";
249 case lexy::code_point::Cn:
250 return "code-point.not-assigned";
257 #if LEXY_HAS_UNICODE_DATABASE
263 return general_category_t::unassigned;
276 return code_point(char32_t(std::int_least32_t(cp.value()) + offset));
284 constexpr
auto mask = ((1 << Props) | ...);
288 return (props & mask) != 0;
292 # define LEXY_UNICODE_PROPERTY(Name) ::lexy::_unicode_db::Name
297 template <
int... Props>
301 # define LEXY_UNICODE_PROPERTY(Name) 0
305 #endif // LEXY_CODE_POINT_HPP_INCLUDED