summaryrefslogtreecommitdiffstats
path: root/generic/tclClockFmt.c
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2024-04-17 14:58:19 (GMT)
committersebres <sebres@users.sourceforge.net>2024-04-17 14:58:19 (GMT)
commit551d70451a01ed8cf74c263b336775c5954c3132 (patch)
tree908af46ca27562d4601b5fda1ad482d4057ff4e7 /generic/tclClockFmt.c
parent5c3d78d478bf289c90dc4e93f3e7455110d49fd0 (diff)
parentf2a5b9f2cdd06e68286da869cd24963c5c2a52fb (diff)
downloadtcl-551d70451a01ed8cf74c263b336775c5954c3132.zip
tcl-551d70451a01ed8cf74c263b336775c5954c3132.tar.gz
tcl-551d70451a01ed8cf74c263b336775c5954c3132.tar.bz2
merge 8.7 (clock compat repair)
Diffstat (limited to 'generic/tclClockFmt.c')
-rw-r--r--generic/tclClockFmt.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index 40c6c92..4ab2423 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -28,6 +28,10 @@ TCL_DECLARE_MUTEX(ClockFmtMutex); /* Serializes access to common format list. */
static void ClockFmtScnStorageDelete(ClockFmtScnStorage *fss);
static void ClockFrmScnFinalize(void *);
+#ifndef TCL_CLOCK_FULL_COMPAT
+#define TCL_CLOCK_FULL_COMPAT 1
+#endif
+
/*
* Derivation of tclStringHashKeyType with another allocEntryProc
*/
@@ -1019,7 +1023,8 @@ static const char *
FindTokenBegin(
const char *p,
const char *end,
- ClockScanToken *tok)
+ ClockScanToken *tok,
+ int flags)
{
if (p < end) {
char c;
@@ -1028,15 +1033,19 @@ FindTokenBegin(
switch (tok->map->type) {
case CTOKT_INT:
case CTOKT_WIDE:
- /* should match at least one digit */
- while (!isdigit(UCHAR(*p)) && (p = Tcl_UtfNext(p)) < end) {}
+ if (!(flags & CLF_STRICT)) {
+ /* should match at least one digit or space */
+ while (!isdigit(UCHAR(*p)) && !isspace(UCHAR(*p)) &&
+ (p = Tcl_UtfNext(p)) < end) {}
+ } else {
+ /* should match at least one digit */
+ while (!isdigit(UCHAR(*p)) && (p = Tcl_UtfNext(p)) < end) {}
+ }
return p;
case CTOKT_WORD:
c = *(tok->tokWord.start);
- /* should match at least to the first char of this word */
- while (*p != c && (p = Tcl_UtfNext(p)) < end) {}
- return p;
+ goto findChar;
case CTOKT_SPACE:
while (!isspace(UCHAR(*p)) && (p = Tcl_UtfNext(p)) < end) {}
@@ -1044,7 +1053,15 @@ FindTokenBegin(
case CTOKT_CHAR:
c = *((char *)tok->map->data);
- while (*p != c && (p = Tcl_UtfNext(p)) < end) {}
+findChar:
+ if (!(flags & CLF_STRICT)) {
+ /* should match the char or space */
+ while (*p != c && !isspace(UCHAR(*p)) &&
+ (p = Tcl_UtfNext(p)) < end) {}
+ } else {
+ /* should match the char */
+ while (*p != c && (p = Tcl_UtfNext(p)) < end) {}
+ }
return p;
}
}
@@ -1069,6 +1086,7 @@ FindTokenBegin(
static void
DetermineGreedySearchLen(
+ ClockFmtScnCmdArgs *opts,
DateInfo *info,
ClockScanToken *tok,
int *minLenPtr,
@@ -1083,7 +1101,8 @@ DetermineGreedySearchLen(
if ((tok + 1)->map) {
end -= tok->endDistance + yySpaceCount;
/* find position of next known token */
- p = FindTokenBegin(p, end, tok + 1);
+ p = FindTokenBegin(p, end, tok + 1,
+ TCL_CLOCK_FULL_COMPAT ? opts->flags : CLF_STRICT);
if (p < end) {
minLen = p - yyInput;
}
@@ -1134,7 +1153,8 @@ DetermineGreedySearchLen(
/* try to find laTok between [lookAhMin, lookAhMax] */
while (minLen < maxLen) {
- const char *f = FindTokenBegin(p, end, laTok);
+ const char *f = FindTokenBegin(p, end, laTok,
+ TCL_CLOCK_FULL_COMPAT ? opts->flags : CLF_STRICT);
/* if found (not below lookAhMax) */
if (f < end) {
break;
@@ -1518,7 +1538,7 @@ ClockScnToken_Month_Proc(
int minLen, maxLen;
TclStrIdxTree *idxTree;
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
/* get or create tree in msgcat dict */
@@ -1550,7 +1570,7 @@ ClockScnToken_DayOfWeek_Proc(
char curTok = *tok->tokWord.start;
TclStrIdxTree *idxTree;
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
/* %u %w %Ou %Ow */
if (curTok != 'a' && curTok != 'A'
@@ -1621,7 +1641,7 @@ ClockScnToken_amPmInd_Proc(
int minLen, maxLen;
Tcl_Obj *amPmObj[2];
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
amPmObj[0] = ClockMCGet(opts, MCLIT_AM);
amPmObj[1] = ClockMCGet(opts, MCLIT_PM);
@@ -1656,7 +1676,7 @@ ClockScnToken_LocaleERA_Proc(
int minLen, maxLen;
Tcl_Obj *eraObj[6];
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
eraObj[0] = ClockMCGet(opts, MCLIT_BCE);
eraObj[1] = ClockMCGet(opts, MCLIT_CE);
@@ -1693,7 +1713,7 @@ ClockScnToken_LocaleListMatcher_Proc(
int minLen, maxLen;
TclStrIdxTree *idxTree;
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
/* get or create tree in msgcat dict */
@@ -1716,7 +1736,7 @@ ClockScnToken_LocaleListMatcher_Proc(
static int
ClockScnToken_JDN_Proc(
- TCL_UNUSED(ClockFmtScnCmdArgs *),
+ ClockFmtScnCmdArgs *opts,
DateInfo *info,
ClockScanToken *tok)
{
@@ -1725,7 +1745,7 @@ ClockScnToken_JDN_Proc(
Tcl_WideInt intJD;
int fractJD = 0, fractJDDiv = 1;
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
end = yyInput + maxLen;
@@ -1796,7 +1816,7 @@ ClockScnToken_TimeZone_Proc(
const char *p = yyInput;
Tcl_Obj *tzObjStor = NULL;
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
/* numeric timezone */
if (*p == '+' || *p == '-') {
@@ -1879,7 +1899,7 @@ ClockScnToken_TimeZone_Proc(
static int
ClockScnToken_StarDate_Proc(
- TCL_UNUSED(ClockFmtScnCmdArgs *),
+ ClockFmtScnCmdArgs *opts,
DateInfo *info,
ClockScanToken *tok)
{
@@ -1888,7 +1908,7 @@ ClockScnToken_StarDate_Proc(
int year, fractYear, fractDayDiv, fractDay;
static const char *stardatePref = "stardate ";
- DetermineGreedySearchLen(info, tok, &minLen, &maxLen);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
end = yyInput + maxLen;
@@ -2436,7 +2456,7 @@ ClockScan(
}
}
- DetermineGreedySearchLen(info, tok, &minLen, &size);
+ DetermineGreedySearchLen(opts, info, tok, &minLen, &size);
if (size < map->minSize) {
/* missing input -> error */