diff options
author | hershey <hershey@noemail.net> | 1999-04-30 16:22:24 (GMT) |
---|---|---|
committer | hershey <hershey@noemail.net> | 1999-04-30 16:22:24 (GMT) |
commit | 0a20d911e0b81832d173ea7e07c079875292de0b (patch) | |
tree | 493586685f7abaad6ae4828c1b4297c6122d5ef7 /generic/tclUtf.c | |
parent | e47f3e12b1e007abfc1f3a7293839d58b4ab7ad6 (diff) | |
download | tcl-0a20d911e0b81832d173ea7e07c079875292de0b.zip tcl-0a20d911e0b81832d173ea7e07c079875292de0b.tar.gz tcl-0a20d911e0b81832d173ea7e07c079875292de0b.tar.bz2 |
Tcl_UtfToUpper and Tcl_UtfToTitle now works on badly formed Utf strings.
FossilOrigin-Name: 8cc1ac50959e95dfd19aa8aa799da4e92c157553
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index a04dca8..0c46d26 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUtf.c,v 1.3 1999/04/29 00:04:41 hershey Exp $ + * RCS: @(#) $Id: tclUtf.c,v 1.4 1999/04/30 16:22:24 hershey Exp $ */ #include "tclInt.h" @@ -1006,8 +1006,9 @@ int Tcl_UtfToTitle(str) char *str; /* String to convert in place. */ { - Tcl_UniChar ch; + Tcl_UniChar ch, titleChar, lowChar; char *src, *dst; + int bytes; /* * Capitalize the first character and then lowercase the rest of the @@ -1017,12 +1018,28 @@ Tcl_UtfToTitle(str) src = dst = str; if (*src) { - src += Tcl_UtfToUniChar(src, &ch); - dst += Tcl_UniCharToUtf(Tcl_UniCharToTitle(ch), dst); + bytes = Tcl_UtfToUniChar(src, &ch); + titleChar = Tcl_UniCharToTitle(ch); + + if (bytes < UtfCount(titleChar)) { + memcpy(dst, src, (size_t) bytes); + dst += bytes; + } else { + dst += Tcl_UniCharToUtf(titleChar, dst); + } + src += bytes; } while (*src) { - src += Tcl_UtfToUniChar(src, &ch); - dst += Tcl_UniCharToUtf(Tcl_UniCharToLower(ch), dst); + bytes = Tcl_UtfToUniChar(src, &ch); + lowChar = Tcl_UniCharToLower(ch); + + if (bytes < UtfCount(lowChar)) { + memcpy(dst, src, (size_t) bytes); + dst += bytes; + } else { + dst += Tcl_UniCharToUtf(lowChar, dst); + } + src += bytes; } *dst = '\0'; return (dst - str); |