From 72af7b48d3c6a818b285122cf2a8275a5225e230 Mon Sep 17 00:00:00 2001 From: Jajauma's GitHub Date: Fri, 12 Aug 2022 23:02:44 +0300 Subject: [PATCH] Avoid possible lexer truncation warnings Instead of static_cast calls that convert int to char, literals of type char are now used directly with the value encoded via escape sequence. The benefits are: - code without static_cast is much more compact and expresses intent better - fixed value truncation warning on some compilers (e.g. C4309 on Visual Studio 2017) --- toml/lexer.hpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/toml/lexer.hpp b/toml/lexer.hpp index 5d019a3..a238d1c 100644 --- a/toml/lexer.hpp +++ b/toml/lexer.hpp @@ -264,21 +264,20 @@ using lex_array_table = sequence; using lex_utf8_2byte = sequence< - in_range(0xC2), static_cast(0xDF)>, - in_range(0x80), static_cast(0xBF)> + in_range<'\xC2', '\xDF'>, + in_range<'\x80', '\xBF'> >; using lex_utf8_3byte = sequence(0xE0)>, in_range(0xA0), static_cast(0xBF)>>, - sequence(0xE1), static_cast(0xEC)>, in_range(0x80), static_cast(0xBF)>>, - sequence(0xED)>, in_range(0x80), static_cast(0x9F)>>, - sequence(0xEE), static_cast(0xEF)>, in_range(0x80), static_cast(0xBF)>> - >, in_range(0x80), static_cast(0xBF)>>; + sequence, in_range<'\xA0', '\xBF'>>, + sequence, in_range<'\x80', '\xBF'>>, + sequence, in_range<'\x80', '\x9F'>>, + sequence, in_range<'\x80', '\xBF'>> + >, in_range<'\x80', '\xBF'>>; using lex_utf8_4byte = sequence(0xF0)>, in_range(0x90), static_cast(0xBF)>>, - sequence(0xF1), static_cast(0xF3)>, in_range(0x80), static_cast(0xBF)>>, - sequence(0xF4)>, in_range(0x80), static_cast(0x8F)>> - >, in_range(0x80), static_cast(0xBF)>, - in_range(0x80), static_cast(0xBF)>>; + sequence, in_range<'\x90', '\xBF'>>, + sequence, in_range<'\x80', '\xBF'>>, + sequence, in_range<'\x80', '\x8F'>> + >, in_range<'\x80', '\xBF'>, in_range<'\x80', '\xBF'>>; using lex_utf8_code = either< lex_utf8_1byte, lex_utf8_2byte,