From f6b32c8442a436357885e7193724581862452a11 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 10 Jan 2017 22:30:49 +0000 Subject: list index logic optimized regarding greedy search (don't stop by first found - try to find longest) --- generic/tclClockFmt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c index daedb26..09cbfa4 100644 --- a/generic/tclClockFmt.c +++ b/generic/tclClockFmt.c @@ -514,7 +514,7 @@ LocaleListSearch(ClockFmtScnCmdArgs *opts, int minLen, int maxLen) { Tcl_Obj **lstv; - int lstc, i, l; + int lstc, i, l, lf = -1; const char *s; Tcl_Obj *valObj; @@ -536,16 +536,27 @@ LocaleListSearch(ClockFmtScnCmdArgs *opts, if ( l >= minLen && l <= maxLen && strncasecmp(yyInput, s, l) == 0 ) { + /* found, try to find longest value (greedy search) */ + if (l < maxLen && minLen != maxLen) { + lf = i; + minLen = l + 1; + continue; + } *val = i; yyInput += l; break; } } - /* if not found */ + /* if found */ if (i < lstc) { return TCL_OK; } + if (lf >= 0) { + *val = lf; + yyInput += minLen - 1; + return TCL_OK; + } return TCL_RETURN; } -- cgit v0.12