Go to the documentation of this file.
4 #ifndef LEXY_ENCODING_HPP_INCLUDED
5 #define LEXY_ENCODING_HPP_INCLUDED
32 template <
typename OtherCharType>
45 if constexpr (std::is_unsigned_v<char_type>)
51 auto value =
static_cast<unsigned char>(c);
63 template <
typename OtherCharType>
71 if constexpr (std::is_signed_v<char_type>)
89 template <
typename OtherCharType>
92 return std::is_same_v<OtherCharType, char>;
113 template <
typename OtherCharType>
116 return std::is_same_v<OtherCharType, LEXY_CHAR8_T>;
137 template <
typename OtherCharType>
140 return sizeof(wchar_t) ==
sizeof(char16_t) && std::is_same_v<OtherCharType, wchar_t>;
161 template <
typename OtherCharType>
164 return sizeof(wchar_t) ==
sizeof(char32_t) && std::is_same_v<OtherCharType, wchar_t>;
173 static constexpr int_type to_int_type(char_type c)
182 using char_type = unsigned char;
183 using int_type = int;
185 template <typename OtherCharType>
186 static constexpr bool is_secondary_char_type()
188 return std::is_same_v<OtherCharType, char> || std::is_same_v<OtherCharType, std::byte>;
191 static LEXY_CONSTEVAL int_type eof()
196 static constexpr int_type to_int_type(char_type c)
203 //=== deduce_encoding ===//
206 template <typename CharT>
207 struct _deduce_encoding;
208 template <typename CharT>
209 using deduce_encoding = typename _deduce_encoding<CharT>::type;
212 struct _deduce_encoding<char>
214 #if defined(LEXY_ENCODING_OF_CHAR)
215 using type = LEXY_ENCODING_OF_CHAR;
216 static_assert(std::is_same_v<type, default_encoding> //
217 || std::is_same_v<type, ascii_encoding> //
218 || std::is_same_v<type, utf8_encoding> //
219 || std::is_same_v<type, utf8_char_encoding>,
220 "invalid value for LEXY_ENCODING_OF_CHAR");
222 using type = default_encoding; // Don't know the exact encoding.
259 template <
typename Encoding>
261 = std::is_same_v<Encoding, ascii_encoding> || std::is_same_v<Encoding, utf8_encoding>
262 || std::is_same_v<Encoding, utf8_char_encoding> || std::is_same_v<Encoding, utf16_encoding>
263 || std::is_same_v<Encoding, utf32_encoding>;
265 template <
typename Encoding>
267 = is_unicode_encoding<Encoding> || std::is_same_v<Encoding, default_encoding>;
269 template <
typename Encoding>
272 template <
typename Encoding>
273 constexpr
auto is_char_encoding = is_text_encoding<Encoding> || is_byte_encoding<Encoding>;
275 template <
typename Encoding>
282 template <
typename Encoding,
typename CharT>
284 || Encoding::template is_secondary_char_type<CharT>();
286 template <
typename Encoding,
typename CharT>
288 = std::enable_if_t<Encoding::template is_secondary_char_type<CharT>()>;
290 template <
typename CharT>
293 if constexpr (std::is_signed_v<CharT>)
294 return 0 <= c && c <= 0x7F;
299 template <
typename TargetCharT,
typename CharT>
302 if constexpr (std::is_same_v<CharT, TargetCharT>)
306 #if !LEXY_HAS_CHAR8_T
307 else if constexpr (std::is_same_v<CharT, char> && std::is_same_v<TargetCharT, LEXY_CHAR8_T>)
318 "so only ASCII characters are supported");
321 return static_cast<TargetCharT
>(c);
325 template <
typename Encoding,
typename CharT>
328 return Encoding::to_int_type(transcode_char<typename Encoding::char_type>(c));
332 #endif // LEXY_ENCODING_HPP_INCLUDED
static constexpr bool is_secondary_char_type()
encoding_endianness
The endianness used by an encoding.
static LEXY_CONSTEVAL int_type eof()
LEXY_CONSTEVAL TargetCharT transcode_char(CharT c)
constexpr auto is_unicode_encoding
std::enable_if_t< Encoding::template is_secondary_char_type< CharT >()> require_secondary_char_type
static constexpr bool is_secondary_char_type()
static constexpr int_type to_int_type(char_type c)
constexpr auto is_byte_encoding
std::int_least32_t int_type
static constexpr int_type to_int_type(char_type c)
static constexpr int_type to_int_type(char_type c)
An encoding where the input is assumed to be valid UTF-32.
static LEXY_CONSTEVAL int_type eof()
static constexpr bool is_secondary_char_type()
constexpr auto is_text_encoding
An encoding where the input is just raw bytes, not characters.
static LEXY_CONSTEVAL int_type eof()
static constexpr bool is_secondary_char_type()
An encoding where the input is assumed to be valid UTF-8.
constexpr bool is_compatible_char_type
constexpr bool is_ascii(CharT c)
static LEXY_CONSTEVAL int_type eof()
An encoding where the input is some 8bit encoding (ASCII, UTF-8, extended ASCII etc....
An encoding where the input is assumed to be valid UTF-8, but the char type is char.
constexpr auto is_char_encoding
An encoding where the input is assumed to be valid UTF-16.
static LEXY_CONSTEVAL int_type eof()
static constexpr bool is_secondary_char_type()
constexpr auto byte
Matches an arbitrary byte.
static constexpr int_type to_int_type(char_type c)
LEXY_CONSTEVAL auto transcode_int(CharT c) -> typename Encoding::int_type
static constexpr int_type to_int_type(char_type c)
static LEXY_CONSTEVAL int_type eof()
static constexpr bool is_secondary_char_type()
#define LEXY_ASSERT(Expr, Msg)
constexpr auto is_node_encoding