15void appendAsciiLiteral(uint32_t utf32, std::string &dst)
19 if (isprint(
int(utf32)))
21 if (strchr(
"\\\'\"",
int(utf32)))
57 const auto t = std::to_chars(buf, buf+
sizeof(buf), utf32, 16);
58 if (t.ec == std::errc())
61 const auto n = t.ptr - buf;
62 dst += n <= 4?
"\\u":
"\\U";
63 if (
const auto nonzeros = n % 4)
64 dst.append(
size_t(4-nonzeros),
'0');
66 dst.append(buf, t.ptr);
70 const auto ecode = make_error_code(t.ec);
71 RUNTIME_ERROR(
"std::to_chars() error: {}:{}", ecode.category().name(), ecode.value());
85 return a.m_Col == b.m_Col &&
86 a.m_Line == b.m_Line &&
87 a.m_Source == b.m_Source;
92 if (a.m_Source == b.m_Source)
93 return a.m_Line < b.m_Line || a.m_Line == b.m_Line && a.m_Col < b.m_Col;
101 appendAsciiLiteral(utf32, ret);
110 while (
const auto t = uin.get(u32))
113 appendAsciiLiteral(u32, ret);
123 static constexpr const char HEX[]{
"0123456789abcdef"};
134 m_Source(sourcePath), m_Line(line), m_Col(col)
139 m_numStr(numstr), m_radix(_radix)
145 m_numStr.insert(std::string::size_type(), 1,
'-');
150 m_numStr.insert(std::string::size_type(), 1,
'+');
153long long C_IntegerLex::value_()
const
156 auto ret = std::stoll(m_numStr, &end, m_radix);
157 if (end < m_numStr.size())
#define RUNTIME_ERROR(fmtStr,...)
Wrap FILE(DATE)#__LINE__ FUNCTION: msg into std::runtime_error.
C_IntegerLex(std::string_view numstr, int _radix) noexcept
THE common namespace of bux library.
bool operator==(const C_SourcePos &a, const C_SourcePos &b) noexcept
Equivalence relation.
bool operator<(const C_SourcePos &a, const C_SourcePos &b) noexcept
Partial relation.
std::string asciiLiteral(uint32_t utf32)
std::uint32_t T_Utf32
UTF-32 to cover the full range of codespace U+0000 ~ U+10FFFF.
void addAsHex(std::string &dst, uint32_t ch32)