@@ -28,6 +28,10 @@ TCL_DECLARE_MUTEX(ClockFmtMutex); /* Serializes access to common format list. */
28
28
static void ClockFmtScnStorageDelete (ClockFmtScnStorage * fss );
29
29
static void ClockFrmScnFinalize (void * );
30
30
31
+ #ifndef TCL_CLOCK_FULL_COMPAT
32
+ #define TCL_CLOCK_FULL_COMPAT 1
33
+ #endif
34
+
31
35
/*
32
36
* Derivation of tclStringHashKeyType with another allocEntryProc
33
37
*/
@@ -1018,7 +1022,8 @@ static const char *
1018
1022
FindTokenBegin (
1019
1023
const char * p ,
1020
1024
const char * end ,
1021
- ClockScanToken * tok )
1025
+ ClockScanToken * tok ,
1026
+ int flags )
1022
1027
{
1023
1028
if (p < end ) {
1024
1029
char c ;
@@ -1027,23 +1032,35 @@ FindTokenBegin(
1027
1032
switch (tok -> map -> type ) {
1028
1033
case CTOKT_INT :
1029
1034
case CTOKT_WIDE :
1030
- /* should match at least one digit */
1031
- while (!isdigit (UCHAR (* p )) && (p = Tcl_UtfNext (p )) < end ) {}
1035
+ if (!(flags & CLF_STRICT )) {
1036
+ /* should match at least one digit or space */
1037
+ while (!isdigit (UCHAR (* p )) && !isspace (UCHAR (* p )) &&
1038
+ (p = Tcl_UtfNext (p )) < end ) {}
1039
+ } else {
1040
+ /* should match at least one digit */
1041
+ while (!isdigit (UCHAR (* p )) && (p = Tcl_UtfNext (p )) < end ) {}
1042
+ }
1032
1043
return p ;
1033
1044
1034
1045
case CTOKT_WORD :
1035
1046
c = * (tok -> tokWord .start );
1036
- /* should match at least to the first char of this word */
1037
- while (* p != c && (p = Tcl_UtfNext (p )) < end ) {}
1038
- return p ;
1047
+ goto findChar ;
1039
1048
1040
1049
case CTOKT_SPACE :
1041
1050
while (!isspace (UCHAR (* p )) && (p = Tcl_UtfNext (p )) < end ) {}
1042
1051
return p ;
1043
1052
1044
1053
case CTOKT_CHAR :
1045
1054
c = * ((char * )tok -> map -> data );
1046
- while (* p != c && (p = Tcl_UtfNext (p )) < end ) {}
1055
+ findChar :
1056
+ if (!(flags & CLF_STRICT )) {
1057
+ /* should match the char or space */
1058
+ while (* p != c && !isspace (UCHAR (* p )) &&
1059
+ (p = Tcl_UtfNext (p )) < end ) {}
1060
+ } else {
1061
+ /* should match the char */
1062
+ while (* p != c && (p = Tcl_UtfNext (p )) < end ) {}
1063
+ }
1047
1064
return p ;
1048
1065
}
1049
1066
}
@@ -1068,6 +1085,7 @@ FindTokenBegin(
1068
1085
1069
1086
static void
1070
1087
DetermineGreedySearchLen (
1088
+ ClockFmtScnCmdArgs * opts ,
1071
1089
DateInfo * info ,
1072
1090
ClockScanToken * tok ,
1073
1091
int * minLenPtr ,
@@ -1082,7 +1100,8 @@ DetermineGreedySearchLen(
1082
1100
if ((tok + 1 )-> map ) {
1083
1101
end -= tok -> endDistance + yySpaceCount ;
1084
1102
/* find position of next known token */
1085
- p = FindTokenBegin (p , end , tok + 1 );
1103
+ p = FindTokenBegin (p , end , tok + 1 ,
1104
+ TCL_CLOCK_FULL_COMPAT ? opts -> flags : CLF_STRICT );
1086
1105
if (p < end ) {
1087
1106
minLen = p - yyInput ;
1088
1107
}
@@ -1133,7 +1152,8 @@ DetermineGreedySearchLen(
1133
1152
1134
1153
/* try to find laTok between [lookAhMin, lookAhMax] */
1135
1154
while (minLen < maxLen ) {
1136
- const char * f = FindTokenBegin (p , end , laTok );
1155
+ const char * f = FindTokenBegin (p , end , laTok ,
1156
+ TCL_CLOCK_FULL_COMPAT ? opts -> flags : CLF_STRICT );
1137
1157
/* if found (not below lookAhMax) */
1138
1158
if (f < end ) {
1139
1159
break ;
@@ -1517,7 +1537,7 @@ ClockScnToken_Month_Proc(
1517
1537
int minLen , maxLen ;
1518
1538
TclStrIdxTree * idxTree ;
1519
1539
1520
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1540
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1521
1541
1522
1542
/* get or create tree in msgcat dict */
1523
1543
@@ -1549,7 +1569,7 @@ ClockScnToken_DayOfWeek_Proc(
1549
1569
char curTok = * tok -> tokWord .start ;
1550
1570
TclStrIdxTree * idxTree ;
1551
1571
1552
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1572
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1553
1573
1554
1574
/* %u %w %Ou %Ow */
1555
1575
if (curTok != 'a' && curTok != 'A'
@@ -1620,7 +1640,7 @@ ClockScnToken_amPmInd_Proc(
1620
1640
int minLen , maxLen ;
1621
1641
Tcl_Obj * amPmObj [2 ];
1622
1642
1623
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1643
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1624
1644
1625
1645
amPmObj [0 ] = ClockMCGet (opts , MCLIT_AM );
1626
1646
amPmObj [1 ] = ClockMCGet (opts , MCLIT_PM );
@@ -1655,7 +1675,7 @@ ClockScnToken_LocaleERA_Proc(
1655
1675
int minLen , maxLen ;
1656
1676
Tcl_Obj * eraObj [6 ];
1657
1677
1658
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1678
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1659
1679
1660
1680
eraObj [0 ] = ClockMCGet (opts , MCLIT_BCE );
1661
1681
eraObj [1 ] = ClockMCGet (opts , MCLIT_CE );
@@ -1692,7 +1712,7 @@ ClockScnToken_LocaleListMatcher_Proc(
1692
1712
int minLen , maxLen ;
1693
1713
TclStrIdxTree * idxTree ;
1694
1714
1695
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1715
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1696
1716
1697
1717
/* get or create tree in msgcat dict */
1698
1718
@@ -1715,7 +1735,7 @@ ClockScnToken_LocaleListMatcher_Proc(
1715
1735
1716
1736
static int
1717
1737
ClockScnToken_JDN_Proc (
1718
- TCL_UNUSED ( ClockFmtScnCmdArgs * ) ,
1738
+ ClockFmtScnCmdArgs * opts ,
1719
1739
DateInfo * info ,
1720
1740
ClockScanToken * tok )
1721
1741
{
@@ -1724,7 +1744,7 @@ ClockScnToken_JDN_Proc(
1724
1744
Tcl_WideInt intJD ;
1725
1745
int fractJD = 0 , fractJDDiv = 1 ;
1726
1746
1727
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1747
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1728
1748
1729
1749
end = yyInput + maxLen ;
1730
1750
@@ -1795,7 +1815,7 @@ ClockScnToken_TimeZone_Proc(
1795
1815
const char * p = yyInput ;
1796
1816
Tcl_Obj * tzObjStor = NULL ;
1797
1817
1798
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1818
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1799
1819
1800
1820
/* numeric timezone */
1801
1821
if (* p == '+' || * p == '-' ) {
@@ -1878,7 +1898,7 @@ ClockScnToken_TimeZone_Proc(
1878
1898
1879
1899
static int
1880
1900
ClockScnToken_StarDate_Proc (
1881
- TCL_UNUSED ( ClockFmtScnCmdArgs * ) ,
1901
+ ClockFmtScnCmdArgs * opts ,
1882
1902
DateInfo * info ,
1883
1903
ClockScanToken * tok )
1884
1904
{
@@ -1887,7 +1907,7 @@ ClockScnToken_StarDate_Proc(
1887
1907
int year , fractYear , fractDayDiv , fractDay ;
1888
1908
static const char * stardatePref = "stardate " ;
1889
1909
1890
- DetermineGreedySearchLen (info , tok , & minLen , & maxLen );
1910
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & maxLen );
1891
1911
1892
1912
end = yyInput + maxLen ;
1893
1913
@@ -2435,7 +2455,7 @@ ClockScan(
2435
2455
}
2436
2456
}
2437
2457
2438
- DetermineGreedySearchLen (info , tok , & minLen , & size );
2458
+ DetermineGreedySearchLen (opts , info , tok , & minLen , & size );
2439
2459
2440
2460
if (size < map -> minSize ) {
2441
2461
/* missing input -> error */
0 commit comments