-#define isIDFIRST_utf8(p) _generic_func_utf8(_CC_IDFIRST, \
- _is_utf8_perl_idstart, p)
-
-#define isLOWER_utf8(p) _generic_swash_utf8(_CC_LOWER, p)
-#define isPRINT_utf8(p) _generic_swash_utf8(_CC_PRINT, p)
-#define isPSXSPC_utf8(p) isSPACE_utf8(p)
-#define isPUNCT_utf8(p) _generic_swash_utf8(_CC_PUNCT, p)
-#define isSPACE_utf8(p) _generic_func_utf8(_CC_SPACE, is_XPERLSPACE_high, p)
-#define isUPPER_utf8(p) _generic_swash_utf8(_CC_UPPER, p)
-#define isVERTWS_utf8(p) _generic_func_utf8(_CC_VERTSPACE, is_VERTWS_high, p)
-#define isWORDCHAR_utf8(p) _generic_swash_utf8(_CC_WORDCHAR, p)
-#define isXDIGIT_utf8(p) _generic_utf8_no_upper_latin1(_CC_XDIGIT, p, \
- is_XDIGIT_high(p))
-
-#define toFOLD_utf8(p,s,l) to_utf8_fold(p,s,l)
-#define toLOWER_utf8(p,s,l) to_utf8_lower(p,s,l)
-#define toTITLE_utf8(p,s,l) to_utf8_title(p,s,l)
-#define toUPPER_utf8(p,s,l) to_utf8_upper(p,s,l)
+#define isIDFIRST_utf8_safe(p, e) \
+ _generic_func_utf8_safe(_CC_IDFIRST, \
+ _is_utf8_perl_idstart, (U8 *) (p), (U8 *) (e))
+
+#define isLOWER_utf8_safe(p, e) _generic_invlist_utf8_safe(_CC_LOWER, p, e)
+#define isPRINT_utf8_safe(p, e) _generic_invlist_utf8_safe(_CC_PRINT, p, e)
+#define isPSXSPC_utf8_safe(p, e) isSPACE_utf8_safe(p, e)
+#define isPUNCT_utf8_safe(p, e) _generic_invlist_utf8_safe(_CC_PUNCT, p, e)
+#define isSPACE_utf8_safe(p, e) \
+ _generic_non_invlist_utf8_safe(_CC_SPACE, is_XPERLSPACE_high, p, e)
+#define isUPPER_utf8_safe(p, e) _generic_invlist_utf8_safe(_CC_UPPER, p, e)
+#define isVERTWS_utf8_safe(p, e) \
+ _generic_non_invlist_utf8_safe(_CC_VERTSPACE, is_VERTWS_high, p, e)
+#define isWORDCHAR_utf8_safe(p, e) \
+ _generic_invlist_utf8_safe(_CC_WORDCHAR, p, e)
+#define isXDIGIT_utf8_safe(p, e) \
+ _generic_utf8_safe_no_upper_latin1(_CC_XDIGIT, p, e, \
+ (UNLIKELY((e) - (p) < UTF8SKIP(p)) \
+ ? (_force_out_malformed_utf8_message( \
+ (U8 *) (p), (U8 *) (e), 0, 1), 0) \
+ : is_XDIGIT_high(p)))
+
+#define toFOLD_utf8(p,e,s,l) toFOLD_utf8_safe(p,e,s,l)
+#define toLOWER_utf8(p,e,s,l) toLOWER_utf8_safe(p,e,s,l)
+#define toTITLE_utf8(p,e,s,l) toTITLE_utf8_safe(p,e,s,l)
+#define toUPPER_utf8(p,e,s,l) toUPPER_utf8_safe(p,e,s,l)
+
+/* For internal core use only, subject to change */
+#define _toFOLD_utf8_flags(p,e,s,l,f) _to_utf8_fold_flags (p,e,s,l,f)
+#define _toLOWER_utf8_flags(p,e,s,l,f) _to_utf8_lower_flags(p,e,s,l,f)
+#define _toTITLE_utf8_flags(p,e,s,l,f) _to_utf8_title_flags(p,e,s,l,f)
+#define _toUPPER_utf8_flags(p,e,s,l,f) _to_utf8_upper_flags(p,e,s,l,f)
+
+#define toFOLD_utf8_safe(p,e,s,l) _toFOLD_utf8_flags(p,e,s,l, FOLD_FLAGS_FULL)
+#define toLOWER_utf8_safe(p,e,s,l) _toLOWER_utf8_flags(p,e,s,l, 0)
+#define toTITLE_utf8_safe(p,e,s,l) _toTITLE_utf8_flags(p,e,s,l, 0)
+#define toUPPER_utf8_safe(p,e,s,l) _toUPPER_utf8_flags(p,e,s,l, 0)
+
+#define isALPHA_LC_utf8(p, e) isALPHA_LC_utf8_safe(p, e)
+#define isALPHANUMERIC_LC_utf8(p, e) isALPHANUMERIC_LC_utf8_safe(p, e)
+#define isASCII_LC_utf8(p, e) isASCII_LC_utf8_safe(p, e)
+#define isBLANK_LC_utf8(p, e) isBLANK_LC_utf8_safe(p, e)
+#define isCNTRL_LC_utf8(p, e) isCNTRL_LC_utf8_safe(p, e)
+#define isDIGIT_LC_utf8(p, e) isDIGIT_LC_utf8_safe(p, e)
+#define isGRAPH_LC_utf8(p, e) isGRAPH_LC_utf8_safe(p, e)
+#define isIDCONT_LC_utf8(p, e) isIDCONT_LC_utf8_safe(p, e)
+#define isIDFIRST_LC_utf8(p, e) isIDFIRST_LC_utf8_safe(p, e)
+#define isLOWER_LC_utf8(p, e) isLOWER_LC_utf8_safe(p, e)
+#define isPRINT_LC_utf8(p, e) isPRINT_LC_utf8_safe(p, e)
+#define isPSXSPC_LC_utf8(p, e) isPSXSPC_LC_utf8_safe(p, e)
+#define isPUNCT_LC_utf8(p, e) isPUNCT_LC_utf8_safe(p, e)
+#define isSPACE_LC_utf8(p, e) isSPACE_LC_utf8_safe(p, e)
+#define isUPPER_LC_utf8(p, e) isUPPER_LC_utf8_safe(p, e)
+#define isWORDCHAR_LC_utf8(p, e) isWORDCHAR_LC_utf8_safe(p, e)
+#define isXDIGIT_LC_utf8(p, e) isXDIGIT_LC_utf8_safe(p, e)