END_EXTERN_C
+#if defined(_MSC_VER) && _MSC_VER < 1400
+/* older MSVC versions have a smallish macro buffer */
+#define PERL_SMALL_MACRO_BUFFER
+#endif
+
/* Native character to/from iso-8859-1. Are the identity functions on ASCII
* platforms */
+#ifdef PERL_SMALL_MACRO_BUFFER
+#define NATIVE_TO_LATIN1(ch) ((U8)(ch))
+#define LATIN1_TO_NATIVE(ch) ((U8)(ch))
+#else
#define NATIVE_TO_LATIN1(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
#define LATIN1_TO_NATIVE(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
+#endif
/* I8 is an intermediate version of UTF-8 used only in UTF-EBCDIC. We thus
* consider it to be identical to UTF-8 on ASCII platforms. Strictly speaking
* because they are 8-bit encodings that serve the same purpose in Perl, and
* rarely do we need to distinguish them. The term "NATIVE_UTF8" applies to
* whichever one is applicable on the current platform */
+#ifdef PERL_SMALL_MACRO_BUFFER
+#define NATIVE_UTF8_TO_I8(ch) (ch)
+#define I8_TO_NATIVE_UTF8(ch) (ch)
+#else
#define NATIVE_UTF8_TO_I8(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
#define I8_TO_NATIVE_UTF8(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
+#endif
/* Transforms in wide UV chars */
#define UNI_TO_NATIVE(ch) ((UV) (ch))
* illegal overlong sequences that begin with C0 and C1. */
#define UTF8_IS_START(c) (((U8)c) >= 0xc2)
+/* For use in UTF8_IS_CONTINUATION() below */
+#define UTF_IS_CONTINUATION_MASK 0xC0
+
/* Is the byte 'c' part of a multi-byte UTF8-8 encoded sequence, and not the
* first byte thereof? */
-#define UTF8_IS_CONTINUATION(c) ((((U8)c) & 0xC0) == UTF_CONTINUATION_MARK)
+#define UTF8_IS_CONTINUATION(c) \
+ ((((U8)c) & UTF_IS_CONTINUATION_MASK) == UTF_CONTINUATION_MARK)
/* Is the UTF8-encoded byte 'c' the first byte of a two byte sequence? Use
* UTF8_IS_NEXT_CHAR_DOWNGRADEABLE() instead if the input isn't known to
* real information */
#define UTF_ACCUMULATION_SHIFT 6
-#if UVSIZE >= 8
-# define UTF8_QUAD_MAX UINT64_C(0x1000000000)
-#endif
+/* ^? 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
+ * those to to quickly exclude the vast majority of code points it will
+ * encounter */
+#define isUTF8_POSSIBLY_PROBLEMATIC(c) ((U8) c >= 0xED)
+
+#endif /* EBCDIC vs ASCII */
+
+/* 2**UTF_ACCUMULATION_SHIFT - 1 */
+#define UTF_CONTINUATION_MASK ((U8) ((1U << UTF_ACCUMULATION_SHIFT) - 1))
/* Internal macro to be used only in this file to aid in constructing other
* publicly accessible macros.
/* 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
+ * For any-sized EBCDIC platforms, or 64-bit ASCII ones, 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
+#if defined(UV_IS_QUAD) || defined(EBCDIC)
# define __BASE_UNI_SKIP(uv) (__COMMON_UNI_SKIP(uv) \
(UV) (uv) < ((UV) 1U << (6 * UTF_ACCUMULATION_SHIFT)) ? 7 : UTF8_MAXBYTES)
#else
# 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
+/* The next two macros use the base macro defined above, and add in the tests
+ * at the low-end of the range, for just 1 byte, yielding complete macros,
+ * publicly accessible. */
+
+/* Input is a true Unicode (not-native) code point */
+#define OFFUNISKIP(uv) (OFFUNI_IS_INVARIANT(uv) ? 1 : __BASE_UNI_SKIP(uv))
-/* Surrogates, non-character code points and above-Unicode code points are
- * problematic in some contexts. This allows code that needs to check for
- * those to to quickly exclude the vast majority of code points it will
- * encounter */
-#define isUTF8_POSSIBLY_PROBLEMATIC(c) ((U8) c >= 0xED)
-#define OFFUNISKIP(uv) ( OFFUNI_IS_INVARIANT(uv) ? 1 : __BASE_UNI_SKIP(uv))
/*
=for apidoc Am|STRLEN|UVCHR_SKIP|UV cp
*/
#define UVCHR_SKIP(uv) ( UVCHR_IS_INVARIANT(uv) ? 1 : __BASE_UNI_SKIP(uv))
-
-#endif /* EBCDIC vs ASCII */
-
-/* 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 */
+/* As explained in the comments for __COMMON_UNI_SKIP, 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 NATIVE8_TO_UNI(ch) NATIVE_TO_LATIN1(ch)
/* This defines the 1-bits that are to be in the first byte of a multi-byte
- * UTF-8 encoded character that give the number of bytes that comprise the
- * character. 'len' is the number of bytes in the multi-byte sequence. */
+ * UTF-8 encoded character that mark it as a start byte and give the number of
+ * bytes that comprise the character. 'len' is the number of bytes in the
+ * multi-byte sequence. */
#define UTF_START_MARK(len) (((len) > 7) ? 0xFF : (0xFF & (0xFE << (7-(len)))))
/* Masks out the initial one bits in a start byte, leaving the real data ones.
* Note that the result can be larger than 255 if the input character is not
* downgradable */
#define TWO_BYTE_UTF8_TO_NATIVE(HI, LO) \
- ( __ASSERT_(UTF8SKIP(HI) == 2) \
+ ( __ASSERT_(PL_utf8skip[HI] == 2) \
__ASSERT_(UTF8_IS_CONTINUATION(LO)) \
UNI_TO_NATIVE(UTF8_ACCUMULATE((NATIVE_UTF8_TO_I8(HI) & UTF_START_MASK(2)), \
(LO))))
* (which works for code points up through 0xFF) or NATIVE_TO_UNI which works
* for any code point */
#define __BASE_TWO_BYTE_HI(c, translate_function) \
+ (__ASSERT_(! UVCHR_IS_INVARIANT(c)) \
I8_TO_NATIVE_UTF8((translate_function(c) >> UTF_ACCUMULATION_SHIFT) \
- | UTF_START_MARK(2))
+ | UTF_START_MARK(2)))
#define __BASE_TWO_BYTE_LO(c, translate_function) \
+ (__ASSERT_(! UVCHR_IS_INVARIANT(c)) \
I8_TO_NATIVE_UTF8((translate_function(c) & UTF_CONTINUATION_MASK) \
- | UTF_CONTINUATION_MARK)
+ | UTF_CONTINUATION_MARK))
/* The next two macros should not be used. They were designed to be usable as
* the case label of a switch statement, but this doesn't work for EBCDIC. Use
* beginning of a utf8 character. Now that foo_utf8() determines that itself,
* no need to do it again here
*/
-#define isIDFIRST_lazy_if(p,UTF) ((IN_BYTES || !UTF ) \
- ? isIDFIRST(*(p)) \
+#define isIDFIRST_lazy_if(p,UTF) ((IN_BYTES || !UTF) \
+ ? isIDFIRST(*(p)) \
: isIDFIRST_utf8((const U8*)p))
-#define isWORDCHAR_lazy_if(p,UTF) ((IN_BYTES || (!UTF )) \
- ? isWORDCHAR(*(p)) \
+#define isWORDCHAR_lazy_if(p,UTF) ((IN_BYTES || (!UTF)) \
+ ? isWORDCHAR(*(p)) \
: isWORDCHAR_utf8((const U8*)p))
#define isALNUM_lazy_if(p,UTF) isWORDCHAR_lazy_if(p,UTF)
#define UNICODE_ALLOW_SUPER 0
#define UNICODE_ALLOW_ANY 0
-#define UNICODE_IS_SURROGATE(c) ((c) >= UNICODE_SURROGATE_FIRST && \
- (c) <= UNICODE_SURROGATE_LAST)
-#define UNICODE_IS_REPLACEMENT(c) ((c) == UNICODE_REPLACEMENT)
-#define UNICODE_IS_BYTE_ORDER_MARK(c) ((c) == UNICODE_BYTE_ORDER_MARK)
-#define UNICODE_IS_NONCHAR(c) ((c >= 0xFDD0 && c <= 0xFDEF) \
- /* The other noncharacters end in FFFE or FFFF, which \
- * the mask below catches both of, but beyond the last \
- * official unicode code point, they aren't \
- * noncharacters, since those aren't Unicode \
- * characters at all */ \
- || ((((c & 0xFFFE) == 0xFFFE)) && ! UNICODE_IS_SUPER(c)))
-#define UNICODE_IS_SUPER(c) ((c) > PERL_UNICODE_MAX)
+/* This matches the 2048 code points between UNICODE_SURROGATE_FIRST (0xD800) and
+ * UNICODE_SURROGATE_LAST (0xDFFF) */
+#define UNICODE_IS_SURROGATE(uv) (((UV) (uv) & (~0xFFFF | 0xF800)) \
+ == 0xD800)
+
+#define UNICODE_IS_REPLACEMENT(uv) ((UV) (uv) == UNICODE_REPLACEMENT)
+#define UNICODE_IS_BYTE_ORDER_MARK(uv) ((UV) (uv) == UNICODE_BYTE_ORDER_MARK)
+
+/* Is 'uv' one of the 32 contiguous-range noncharacters? */
+#define UNICODE_IS_32_CONTIGUOUS_NONCHARS(uv) ((UV) (uv) >= 0xFDD0 \
+ && (UV) (uv) <= 0xFDEF)
+
+/* Is 'uv' one of the 34 plane-ending noncharacters 0xFFFE, 0xFFFF, 0x1FFFE,
+ * 0x1FFFF, ... 0x10FFFE, 0x10FFFF, given that we know that 'uv' is not above
+ * the Unicode legal max */
+#define UNICODE_IS_END_PLANE_NONCHAR_GIVEN_NOT_SUPER(uv) \
+ (((UV) (uv) & 0xFFFE) == 0xFFFE)
+
+#define UNICODE_IS_NONCHAR(uv) \
+ ( UNICODE_IS_32_CONTIGUOUS_NONCHARS(uv) \
+ || ( LIKELY( ! UNICODE_IS_SUPER(uv)) \
+ && UNICODE_IS_END_PLANE_NONCHAR_GIVEN_NOT_SUPER(uv)))
+
+#define UNICODE_IS_SUPER(uv) ((UV) (uv) > PERL_UNICODE_MAX)
#define UNICODE_IS_ABOVE_31_BIT(uv) ((UV) (uv) > 0x7FFFFFFF)
#define LATIN_SMALL_LETTER_SHARP_S LATIN_SMALL_LETTER_SHARP_S_NATIVE