From f223db50fda34233096578863259fadfb133e804 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 10 Mar 2021 16:12:01 +0000 Subject: Repair Tcl_UniCharNcasecmp() in the same way as Tcl_UniCharNcmp() for fix [4c591fa487]. Also put back minor optimization for big-endian machines removed in the previous commit --- generic/tclUtf.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 6e6d386..bcae055 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1592,6 +1592,14 @@ Tcl_UniCharNcmp( const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ unsigned long numChars) /* Number of unichars to compare. */ { +#if defined(WORDS_BIGENDIAN) && (TCL_UTF_MAX != 4) + /* + * We are definitely on a big-endian machine; memcmp() is safe + */ + + return memcmp(ucs, uct, numChars*sizeof(Tcl_UniChar)); + +#else /* !WORDS_BIGENDIAN */ /* * We can't simply call memcmp() because that is not lexically correct. */ @@ -1610,6 +1618,7 @@ Tcl_UniCharNcmp( } } return 0; +#endif /* WORDS_BIGENDIAN */ } /* @@ -1642,6 +1651,14 @@ Tcl_UniCharNcasecmp( Tcl_UniChar lct = Tcl_UniCharToLower(*uct); if (lcs != lct) { +#if TCL_UTF_MAX == 4 + /* special case for handling upper surrogates */ + if (((lcs & 0xFC00) == 0xD800) && ((lct & 0xFC00) != 0xD800)) { + return 1; + } else if (((lct & 0xFC00) == 0xD800)) { + return -1; + } +#endif return (lcs - lct); } } -- cgit v0.12