diff options
| author | donal.k.fellows@manchester.ac.uk <dkf> | 2013-05-22 12:59:45 (GMT) |
|---|---|---|
| committer | donal.k.fellows@manchester.ac.uk <dkf> | 2013-05-22 12:59:45 (GMT) |
| commit | ae092efa7333772a2e727927c92ace2d7574c613 (patch) | |
| tree | 218f3ee1b36b96a9c5be01173b1c55abc142432e /generic/tclUtf.c | |
| parent | 4c775be3c6ac6c42c3c28762b6e199b7182c475c (diff) | |
| parent | 489928c237e0189f069bb2aec3f28e424d492bca (diff) | |
| download | tcl-ae092efa7333772a2e727927c92ace2d7574c613.zip tcl-ae092efa7333772a2e727927c92ace2d7574c613.tar.gz tcl-ae092efa7333772a2e727927c92ace2d7574c613.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 83900e9..f3d1758 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1105,6 +1105,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. |
