-#define isodigit(c) ('0' <= (c) && (c) <= '7')
-#define octtobin(c) ((c) - '0')
-/* FIXME-maybe: macros names may be misleading: "bin" may be interpreted as
- "having a value of (char)'0' or (char)'1'". Rename? `hextonative`?
- `hextoint`? */
-#define hextobin(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
+#define isoct(c) ('0' <= (c) && (c) <= '7')
+#define fromoct(c) ((c) - '0')
+#define fromhex(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
'A' <= (c) && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
for (esc_length = 0, ++p;
esc_length < 2 && c_isxdigit (to_uchar (*p));
++esc_length, ++p)
- esc_value = esc_value * 16 + hextobin (*p);
+ esc_value = esc_value * 16 + fromhex (*p);
if (esc_length == 0)
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
putchar (esc_value);
}
- else if (isodigit (*p))
+ else if (isoct (*p))
{
/* Parse \0ooo (if octal_0 && *p == '0') or \ooo (otherwise).
Allow \ooo if octal_0 && *p != '0'; this is an undocumented
extension to POSIX that is compatible with Bash 2.05b. */
for (esc_length = 0, p += octal_0 && *p == '0';
- esc_length < 3 && isodigit (*p);
+ esc_length < 3 && isoct (*p);
++esc_length, ++p)
- esc_value = esc_value * 8 + octtobin (*p);
+ esc_value = esc_value * 8 + fromoct (*p);
putchar (esc_value);
}
else if (*p && strchr ("\"\\abcefnrtv", *p))
{
if (! c_isxdigit (to_uchar (*p)))
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
- uni_value = uni_value * 16 + hextobin (*p);
+ uni_value = uni_value * 16 + fromhex (*p);
}
/* Error for invalid code points 0000D800 through 0000DFFF inclusive.
break;
}
++b;
- if (isodigit (*b))
+ if (isoct (*b))
{
- int esc_value = octtobin (*b);
+ int esc_value = fromoct (*b);
int esc_length = 1; /* number of octal digits */
- for (++b; esc_length < 3 && isodigit (*b);
+ for (++b; esc_length < 3 && isoct (*b);
++esc_length, ++b)
{
- esc_value = esc_value * 8 + octtobin (*b);
+ esc_value = esc_value * 8 + fromoct (*b);
}
putchar (esc_value);
--b;
}
else if (*b == 'x' && c_isxdigit (to_uchar (b[1])))
{
- int esc_value = hextobin (b[1]); /* Value of \xhh escape. */
+ int esc_value = fromhex (b[1]); /* Value of \xhh escape. */
/* A hexadecimal \xhh escape sequence must have
1 or 2 hex. digits. */
++b;
if (c_isxdigit (to_uchar (b[1])))
{
++b;
- esc_value = esc_value * 16 + hextobin (*b);
+ esc_value = esc_value * 16 + fromhex (*b);
}
putchar (esc_value);
}