if (dFlag && encoding.is (Enc::EBCDIC))
{
const uint32_t c = encoding.decodeUnsafe (b);
- if (isprint (c))
+ if (is_print (c))
o << " /* " << static_cast<char> (c) << " */";
}
bool last_case = i == ranges.size () - 1 && b == ranges[i].second - 1;
namespace re2c
{
+bool is_print (uint32_t c)
+{
+ return c >= 0x20 && c < 0x7F;
+}
+
+bool is_space (uint32_t c)
+{
+ switch (c)
+ {
+ case '\t':
+ case '\f':
+ case '\v':
+ case '\n':
+ case '\r':
+ case ' ':
+ return true;
+ default:
+ return false;
+ }
+}
+
char hexCh(uint32_t c)
{
static const char * sHex = "0123456789ABCDEF";
void prtChOrHex(std::ostream& o, uint32_t c)
{
- if (!encoding.is(Enc::EBCDIC) && (c < 256u) && (isprint(c) || isspace(c)))
+ if (!encoding.is (Enc::EBCDIC)
+ && (is_print (c) || is_space (c)))
{
o << '\'';
prtCh(o, c);
void prtHex(std::ostream& o, uint32_t c)
{
- int oc = (int)(c);
-
- if (encoding.szCodeUnit() == 4)
- {
- o << "0x"
- << hexCh(oc >> 28)
- << hexCh(oc >> 24)
- << hexCh(oc >> 20)
- << hexCh(oc >> 16)
- << hexCh(oc >> 12)
- << hexCh(oc >> 8)
- << hexCh(oc >> 4)
- << hexCh(oc);
- }
- else if (encoding.szCodeUnit() == 2)
+ o << "0x";
+ const uint32_t cunit_size = encoding.szCodeUnit ();
+ if (cunit_size >= 4)
{
- o << "0x"
- << hexCh(oc >> 12)
- << hexCh(oc >> 8)
- << hexCh(oc >> 4)
- << hexCh(oc);
+ o << hexCh (c >> 28u)
+ << hexCh (c >> 24u)
+ << hexCh (c >> 20u)
+ << hexCh (c >> 16u);
}
- else
+ if (cunit_size >= 2)
{
- o << "0x"
- << hexCh(oc >> 4)
- << hexCh(oc);
+ o << hexCh (c >> 12u)
+ << hexCh (c >> 8u);
}
+ o << hexCh (c >> 4u)
+ << hexCh (c);
}
void prtCh(std::ostream& o, uint32_t c)
void prtChOrHexForSpan(std::ostream& o, uint32_t c)
{
- if (!encoding.is(Enc::EBCDIC) && (c < 256u) && isprint(c) && (c != ']'))
+ if (!encoding.is(Enc::EBCDIC)
+ && is_print (c)
+ && (c != ']'))
{
prtCh(o, c);
}
namespace re2c
{
+bool is_print (uint32_t c);
+bool is_space (uint32_t c);
char hexCh(uint32_t c);
void prtCh(std::ostream&, uint32_t);
void prtHex(std::ostream&, uint32_t);