This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.h: Refactor a macro
[perl5.git] / utf8.h
diff --git a/utf8.h b/utf8.h
index 8a78496..129356e 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -243,29 +243,29 @@ Perl's extended UTF-8 means we can have start bytes up to FF.
 
 #if UVSIZE >= 8
 #  define UTF8_QUAD_MAX UINT64_C(0x1000000000)
+#endif
 
 /* Input is a true Unicode (not-native) code point */
-#define OFFUNISKIP(uv) ( (uv) < 0x80        ? 1 : \
+#define __COMMON_UNI_SKIP(uv)                                               \
                      (uv) < 0x800          ? 2 : \
                      (uv) < 0x10000        ? 3 : \
                      (uv) < 0x200000       ? 4 : \
                      (uv) < 0x4000000      ? 5 : \
-                     (uv) < 0x80000000     ? 6 : \
-                      (uv) < UTF8_QUAD_MAX ? 7 : UTF8_MAXBYTES )
+                     (uv) < 0x80000000     ? 6 :
+
+/* Internal macro to be used only in this file.
+ * This adds to __COMMON_UNI_SKIP the details at this platform's upper range.
+ * For 64-bit ASCII platforms, we need one more test
+ * to see if just 7 bytes is needed, or if the maximum is needed.  For 32-bit
+ * ASCII platforms, everything is representable by 7 bytes */
+#ifdef UV_IS_QUAD
+#   define __BASE_UNI_SKIP(uv) (__COMMON_UNI_SKIP(uv)                       \
+     (uv) < UTF8_QUAD_MAX ? 7 : UTF8_MAXBYTES )
 #else
-/* No, I'm not even going to *TRY* putting #ifdef inside a #define */
-#define OFFUNISKIP(uv) ( (uv) < 0x80        ? 1 : \
-                     (uv) < 0x800          ? 2 : \
-                     (uv) < 0x10000        ? 3 : \
-                     (uv) < 0x200000       ? 4 : \
-                     (uv) < 0x4000000      ? 5 : \
-                     (uv) < 0x80000000     ? 6 : 7 )
+#   define __BASE_UNI_SKIP(uv) (__COMMON_UNI_SKIP(uv) 7)
 #endif
 
-/* ^? is defined to be DEL on ASCII systems.  See the definition of toCTRL()
- * for more */
-#define QUESTION_MARK_CTRL  DEL_NATIVE
-
+#define OFFUNISKIP(uv) ( OFFUNI_IS_INVARIANT(uv) ? 1 : __BASE_UNI_SKIP(uv))
 /*
 
 =for apidoc Am|STRLEN|UVCHR_SKIP|UV cp
@@ -275,7 +275,11 @@ encoded as UTF-8.  C<cp> is a native (ASCII or EBCDIC) code point if less than
 
 =cut
  */
-#define UVCHR_SKIP(uv) OFFUNISKIP(uv)
+#define UVCHR_SKIP(uv) ( UVCHR_IS_INVARIANT(uv) ? 1 : __BASE_UNI_SKIP(uv))
+
+/* ^? is defined to be DEL on ASCII systems.  See the definition of toCTRL()
+ * for more */
+#define QUESTION_MARK_CTRL  DEL_NATIVE
 
 /* Surrogates, non-character code points and above-Unicode code points are
  * problematic in some contexts.  This allows code that needs to check for