diff options
author | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:38:56 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:38:56 (GMT) |
commit | 9487f2cdcd7045ccc7f540099755acc0d2b36244 (patch) | |
tree | 4c5454ef6d689584f27bacbb860cdb9390f5c722 | |
parent | fb0ed853e7c49ff24e17f4cb633876d0780b64b5 (diff) | |
download | tcl-9487f2cdcd7045ccc7f540099755acc0d2b36244.zip tcl-9487f2cdcd7045ccc7f540099755acc0d2b36244.tar.gz tcl-9487f2cdcd7045ccc7f540099755acc0d2b36244.tar.bz2 |
locale months scan switched to from list seek to index tree; bug fixing
-rw-r--r-- | generic/tclClockFmt.c | 23 | ||||
-rw-r--r-- | generic/tclDate.h | 4 | ||||
-rw-r--r-- | generic/tclStrIdxTree.h | 2 | ||||
-rw-r--r-- | tests/clock.test | 24 |
4 files changed, 40 insertions, 13 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c index 92040d8..478941b 100644 --- a/generic/tclClockFmt.c +++ b/generic/tclClockFmt.c @@ -682,6 +682,7 @@ ClockMCGetMultiListIdxTree( } ClockMCSetIdx(opts, mcKey, objPtr); + objPtr = NULL; }; done: @@ -788,22 +789,24 @@ ClockScnToken_Month_Proc(ClockFmtScnCmdArgs *opts, return TCL_OK; */ + static int monthsKeys[] = {MCLIT_MONTHS_FULL, MCLIT_MONTHS_ABBREV, 0}; + int ret, val; int minLen, maxLen; + TclStrIdxTree *idxTree; DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen); - ret = LocaleListSearch(opts, info, MCLIT_MONTHS_FULL, &val, - minLen, maxLen); + /* get or create tree in msgcat dict */ + + idxTree = ClockMCGetMultiListIdxTree(opts, MCLIT_MONTHS_COMB, monthsKeys); + if (idxTree == NULL) { + return TCL_ERROR; + } + + ret = ClockStrIdxTreeSearch(opts, info, idxTree, &val, minLen, maxLen); if (ret != TCL_OK) { - /* if not found */ - if (ret == TCL_RETURN) { - ret = LocaleListSearch(opts, info, MCLIT_MONTHS_ABBREV, &val, - minLen, maxLen); - } - if (ret != TCL_OK) { - return ret; - } + return ret; } yyMonth = val + 1; diff --git a/generic/tclDate.h b/generic/tclDate.h index 2728dd3..85bcd35 100644 --- a/generic/tclDate.h +++ b/generic/tclDate.h @@ -104,7 +104,7 @@ typedef enum ClockLiteral { typedef enum ClockMsgCtLiteral { MCLIT__NIL, /* placeholder */ - MCLIT_MONTHS_FULL, MCLIT_MONTHS_ABBREV, + MCLIT_MONTHS_FULL, MCLIT_MONTHS_ABBREV, MCLIT_MONTHS_COMB, MCLIT_DAYS_OF_WEEK_FULL, MCLIT_DAYS_OF_WEEK_ABBREV, MCLIT_AM, MCLIT_PM, MCLIT_BCE, MCLIT_CE, @@ -116,7 +116,7 @@ typedef enum ClockMsgCtLiteral { #define CLOCK_LOCALE_LITERAL_ARRAY(litarr, pref) static const char *const litarr[] = { \ pref "", \ - pref "MONTHS_FULL", pref "MONTHS_ABBREV", \ + pref "MONTHS_FULL", pref "MONTHS_ABBREV", pref "MONTHS_COMB", \ pref "DAYS_OF_WEEK_FULL", pref "DAYS_OF_WEEK_ABBREV", \ pref "AM", pref "PM", \ pref "BCE", pref "CE", \ diff --git a/generic/tclStrIdxTree.h b/generic/tclStrIdxTree.h index d2d6f0b..934e28f 100644 --- a/generic/tclStrIdxTree.h +++ b/generic/tclStrIdxTree.h @@ -111,7 +111,7 @@ TclUtfFindEqualNCInLwr( return ret; } -inline char * +inline const char * TclUtfNext( register const char *src) /* The current location in the string. */ { diff --git a/tests/clock.test b/tests/clock.test index e96dec6..1d02f39 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -18564,6 +18564,30 @@ test clock-6.11 {input of seconds - two values} { clock scan {1 2} -format {%s %s} -gmt true } 2 +test clock-6.12 {input of unambiguous short locale token (%b)} { + list [clock scan "12 Ja 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] \ + [clock scan "12 Au 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] +} {979257600 997574400} +test clock-6.13 {input of lowercase locale token (%b)} { + list [clock scan "12 ja 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] \ + [clock scan "12 au 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] +} {979257600 997574400} +test clock-6.14 {input of uppercase locale token (%b)} { + list [clock scan "12 JA 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] \ + [clock scan "12 AU 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1] +} {979257600 997574400} +test clock-6.15 {input of ambiguous short locale token (%b)} { + list [catch { + clock scan "12 J 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1 + } result] $result $errorCode +} {1 {input string does not match supplied format} {CLOCK badInputString}} +test clock-6.16 {input of ambiguous short locale token (%b)} { + list [catch { + clock scan "12 Ju 2001" -format "%d %b %Y" -locale en_US_roman -gmt 1 + } result] $result $errorCode +} {1 {input string does not match supplied format} {CLOCK badInputString}} + + test clock-7.1 {Julian Day} { clock scan 0 -format %J -gmt true } -210866803200 |