diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2013-05-22 13:07:33 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2013-05-22 13:07:33 (GMT) |
commit | 0e1a083787efebde534b0323ba4cca840630fe71 (patch) | |
tree | 21c32e456ae1ff62b2dbb1b4861118c3330a60c3 /generic/tclUtf.c | |
parent | 6ede2e9a9c11a27ad6be06a3eceda2f98be8f8d5 (diff) | |
parent | a515427b5b0f2be828866a2073b4720681e10e0d (diff) | |
download | tcl-0e1a083787efebde534b0323ba4cca840630fe71.zip tcl-0e1a083787efebde534b0323ba4cca840630fe71.tar.gz tcl-0e1a083787efebde534b0323ba4cca840630fe71.tar.bz2 |
[3613609]: Replace strcasecmp() with UTF-8-aware version.
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 18a82f7..4ad6f01 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1106,6 +1106,46 @@ Tcl_UtfNcasecmp( /* *---------------------------------------------------------------------- * + * Tcl_UtfNcasecmp -- + * + * Compare UTF chars of string cs to string ct case insensitively. + * Replacement for strcasecmp in Tcl core, in places where UTF-8 should + * be handled. + * + * Results: + * Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TclUtfCasecmp( + const char *cs, /* UTF string to compare to ct. */ + const char *ct) /* UTF string cs is compared to. */ +{ + while (*cs && *ct) { + Tcl_UniChar ch1, ch2; + + cs += TclUtfToUniChar(cs, &ch1); + ct += TclUtfToUniChar(ct, &ch2); + if (ch1 != ch2) { + ch1 = Tcl_UniCharToLower(ch1); + ch2 = Tcl_UniCharToLower(ch2); + if (ch1 != ch2) { + return ch1 - ch2; + } + } + } + return UCHAR(*cs) - UCHAR(*ct); +} + + +/* + *---------------------------------------------------------------------- + * * Tcl_UniCharToUpper -- * * Compute the uppercase equivalent of the given Unicode character. |