summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2013-12-31 22:35:46 -0700
committerKarl Williamson <public@khwilliamson.com>2014-01-01 13:49:24 -0700
commitcb27eebd32af3dfebf46f5eb3778fe29175004b5 (patch)
tree9de60225f2a86966728762b65dd4c82f8c5dbcec /handy.h
parent902008b8891cbab762cbca65291391e811857949 (diff)
downloadperl-cb27eebd32af3dfebf46f5eb3778fe29175004b5.tar.gz
handy.h: Add two macros
handy.h contains a macro that reads a hex digit and returns its value, with fewer branches than a naive implementation would use. This commit just copies and modifies it to create two macros for 1) just converting the hex value, without advancing the input; and 2) doing the same for an octal value.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/handy.h b/handy.h
index c4a162d8d2..6b74c87da2 100644
--- a/handy.h
+++ b/handy.h
@@ -1564,14 +1564,23 @@ typedef U32 line_t;
} \
return a;
-/* Converts a hex digit in a string to its numeric value, advancing the
- * pointer. The input must be known to be 0-9, A-F, or a-f. In both ASCII and
- * EBCDIC the last 4 bits of the digits are 0-9; and the last 4 bits of A-F and
- * a-f are 1-6, so adding 9 yields 10-15 */
+/* Converts a character known to represent a hexadecimal digit (0-9, A-F, or
+ * a-f) to its numeric value. READ_XDIGIT's argument is a string pointer,
+ * which is advanced. The input is validated only by an assert() in DEBUGGING
+ * builds. In both ASCII and EBCDIC the last 4 bits of the digits are 0-9; and
+ * the last 4 bits of A-F and a-f are 1-6, so adding 9 yields 10-15 */
+#define XDIGIT_VALUE(c) (__ASSERT_(isXDIGIT(c)) (0xf & (isDIGIT(c) \
+ ? (c) \
+ : ((c) + 9))))
#define READ_XDIGIT(s) (__ASSERT_(isXDIGIT(*s)) (0xf & (isDIGIT(*(s)) \
? (*(s)++) \
: (*(s)++ + 9))))
+/* Converts a character known to represent an octal digit (0-7) to its numeric
+ * value. The input is validated only by an assert() in DEBUGGING builds. In
+ * both ASCII and EBCDIC the last 3 bits of the octal digits range from 0-7. */
+#define OCTAL_VALUE(c) (__ASSERT_(isOCTAL(c)) (7 & (c)))
+
/*
=head1 Memory Management