summaryrefslogtreecommitdiffstats
path: root/generic/tclUtf.c
diff options
context:
space:
mode:
authorhershey <hershey>1999-04-30 16:22:24 (GMT)
committerhershey <hershey>1999-04-30 16:22:24 (GMT)
commitb81b15c0f284194a10d17be0a8daa622ec578d94 (patch)
tree493586685f7abaad6ae4828c1b4297c6122d5ef7 /generic/tclUtf.c
parentb069872348a67599dd626cf695fda15eab91fe02 (diff)
downloadtcl-b81b15c0f284194a10d17be0a8daa622ec578d94.zip
tcl-b81b15c0f284194a10d17be0a8daa622ec578d94.tar.gz
tcl-b81b15c0f284194a10d17be0a8daa622ec578d94.tar.bz2
Tcl_UtfToUpper and Tcl_UtfToTitle now works on badly formed Utf strings.
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r--generic/tclUtf.c29
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);