From 04e435eb58be31778370bb38c18952a2d6a782b1 Mon Sep 17 00:00:00 2001 From: rmax Date: Fri, 5 Jul 2002 11:16:01 +0000 Subject: * generic/tclClock.c (FormatClock): Convert the format string to UTF8 before calling TclpStrftime, so that non-ASCII characters don't get mangled when the result string is being converted back. * tests/clock.test: Added a test for that. --- ChangeLog | 7 +++++++ generic/tclClock.c | 9 ++++++--- tests/clock.test | 10 +++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f93b24..119eaa0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-07-05 Reinhard Max + + * generic/tclClock.c (FormatClock): Convert the format string to + UTF8 before calling TclpStrftime, so that non-ASCII characters + don't get mangled when the result string is being converted back. + * tests/clock.test: Added a test for that. + 2002-07-05 Donal K. Fellows * unix/Makefile.in (ro-test,ddd,GDB,DDD): Created new targets to diff --git a/generic/tclClock.c b/generic/tclClock.c index 9bf7ed0..549cc0a 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclClock.c,v 1.15 2002/05/29 00:19:40 hobbs Exp $ + * RCS: @(#) $Id: tclClock.c,v 1.16 2002/07/05 11:16:01 rmax Exp $ */ #include "tcl.h" @@ -327,13 +327,16 @@ FormatClock(interp, clockVal, useGMT, format) bufSize++; } } + Tcl_DStringInit(&uniBuffer); + Tcl_UtfToExternalDString(NULL, format, -1, &uniBuffer); Tcl_DStringInit(&buffer); Tcl_DStringSetLength(&buffer, bufSize); Tcl_MutexLock(&clockMutex); - result = TclpStrftime(buffer.string, (unsigned int) bufSize, format, - timeDataPtr, useGMT); + result = TclpStrftime(buffer.string, (unsigned int) bufSize, + Tcl_DStringValue(&uniBuffer), timeDataPtr, useGMT); Tcl_MutexUnlock(&clockMutex); + Tcl_DStringFree(&uniBuffer); #if !defined(HAVE_TM_ZONE) && !defined(WIN32) if (useGMT) { diff --git a/tests/clock.test b/tests/clock.test index 8f4014e..cc77260 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: clock.test,v 1.20 2002/06/26 13:42:23 rmax Exp $ +# RCS: @(#) $Id: clock.test,v 1.21 2002/07/05 11:16:01 rmax Exp $ set env(LC_TIME) POSIX @@ -114,6 +114,14 @@ test clock-3.11 {clock format tests} { test clock-3.12 {clock format tests} { clock format 123 -format "" } "" +test clock-3.13 {clock format with non-ASCII character in the format string} { + set oldenc [encoding system] + encoding system iso8859-1 + set res [clock format 0 -format \u00c4] + encoding system $oldenc + unset oldenc + set res +} "\u00c4" # clock scan test clock-4.1 {clock scan tests} { -- cgit v0.12