diff options
author | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:30:24 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:30:24 (GMT) |
commit | 40520b8606111adeab272cb9d2fa4c7acca3e406 (patch) | |
tree | d0b0160f1b83e719ad0ec41239e7b2a98aea16cd /library/clock.tcl | |
parent | 5afae758b98de2da47b30d6aa4b40a5d5a604fbc (diff) | |
download | tcl-40520b8606111adeab272cb9d2fa4c7acca3e406.zip tcl-40520b8606111adeab272cb9d2fa4c7acca3e406.tar.gz tcl-40520b8606111adeab272cb9d2fa4c7acca3e406.tar.bz2 |
improve LocalizeFormat, internal caching of localized formats inside msgcat for locale and format objects
smart reference introduced in dict (smart pointer with 0 object reference but increase dict-reference, provide changeable locale dict)
code review
Diffstat (limited to 'library/clock.tcl')
-rwxr-xr-x | library/clock.tcl | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/library/clock.tcl b/library/clock.tcl index 4173174..a532c0d 100755 --- a/library/clock.tcl +++ b/library/clock.tcl @@ -2365,18 +2365,23 @@ proc ::tcl::clock::LocalizeFormat { locale format {fmtkey {}} } { dict set LocaleFormats $locale MLST $mlst } - # translate: - set locfmt [string map $mlst $format] - - # Save original format as long as possible, because of internal representation (performance) - if {$locfmt eq $format} { - set locfmt $format - } + # translate copy of format (don't use format object here, because otherwise + # it can lose its internal representation (string map - convert to unicode) + set locfmt [string map $mlst [string range " $format" 1 end]] # cache it: dict set LocaleFormats $locale $fmtkey $locfmt } + # Save original format as long as possible, because of internal + # representation (performance). + # Note that in this case such format will be never localized (also + # using another locales). To prevent this return a duplicate (but + # it may be slower). + if {$locfmt eq $format} { + set locfmt $format + } + return $locfmt } |