diff options
author | dkf <dkf@noemail.net> | 2013-05-22 13:07:33 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2013-05-22 13:07:33 (GMT) |
commit | 20e15078912f0d84de408f49a573894d9f7069e1 (patch) | |
tree | 21c32e456ae1ff62b2dbb1b4861118c3330a60c3 /generic/tclUtf.c | |
parent | 53e0348d7f8e3501b7299f31bba92ceab7f0117a (diff) | |
parent | d66a931492429c1480908426a9b2af2cb833a52c (diff) | |
download | tcl-20e15078912f0d84de408f49a573894d9f7069e1.zip tcl-20e15078912f0d84de408f49a573894d9f7069e1.tar.gz tcl-20e15078912f0d84de408f49a573894d9f7069e1.tar.bz2 |
[3613609]: Replace strcasecmp() with UTF-8-aware version.
FossilOrigin-Name: 89f027f118c0cae741036295827ac6105d9dc781
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. |