This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.h: Combine EBCDIC and ASCII #defines
authorKarl Williamson <khw@cpan.org>
Fri, 6 Nov 2015 17:06:32 +0000 (10:06 -0700)
committerKarl Williamson <khw@cpan.org>
Sun, 6 Dec 2015 05:06:50 +0000 (22:06 -0700)
Change to use the same definition for two macros on both types of
platforms, simplifying the code, by using the underlying structure of
the encoding.

utf8.h
utfebcdic.h

diff --git a/utf8.h b/utf8.h
index 191daf5..8a78496 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -266,8 +266,6 @@ Perl's extended UTF-8 means we can have start bytes up to FF.
  * for more */
 #define QUESTION_MARK_CTRL  DEL_NATIVE
 
-#define MAX_UTF8_TWO_BYTE 0x7FF
-
 /*
 
 =for apidoc Am|STRLEN|UVCHR_SKIP|UV cp
@@ -290,6 +288,12 @@ encoded as UTF-8.  C<cp> is a native (ASCII or EBCDIC) code point if less than
 /* 2**UTF_ACCUMULATION_SHIFT - 1 */
 #define UTF_CONTINUATION_MASK  ((U8) ((1U << UTF_ACCUMULATION_SHIFT) - 1))
 
+/* 32 start bytes with UTF_ACCUMULATION_SHIFT bits of information each */
+#define MAX_UTF8_TWO_BYTE (32 * (1U << UTF_ACCUMULATION_SHIFT) - 1)
+
+/* constrained by EBCDIC which has 5 bits per continuation byte */
+#define MAX_PORTABLE_UTF8_TWO_BYTE (32 * (1U << 5) - 1)
+
 /* The maximum number of UTF-8 bytes a single Unicode character can
  * uppercase/lowercase/fold into.  Unicode guarantees that the maximum
  * expansion is UTF8_MAX_FOLD_CHAR_EXPAND characters, but any above-Unicode
@@ -420,8 +424,6 @@ only) byte is pointed to by C<s>.
  * above show, doesn't matter as to its implementation */
 #define NATIVE_BYTE_IS_INVARIANT(c)    UVCHR_IS_INVARIANT(c)
 
-#define MAX_PORTABLE_UTF8_TWO_BYTE 0x3FF    /* constrained by EBCDIC */
-
 /* The macros in the next 4 sets are used to generate the two utf8 or utfebcdic
  * bytes from an ordinal that is known to fit into exactly two (not one) bytes;
  * it must be less than 0x3FF to work across both encodings. */
index 9ab6de4..d7716f2 100644 (file)
@@ -239,8 +239,6 @@ above what a 64 bit word can hold */
  * for more */
 #define QUESTION_MARK_CTRL   LATIN1_TO_NATIVE(0x9F)
 
-#define MAX_UTF8_TWO_BYTE 0x3FF
-
 /*
  * ex: set ts=8 sts=4 sw=4 et:
  */