bug fix for timestmap
This commit is contained in:
parent
20bee50b59
commit
836ac94afe
31 changed files with 195 additions and 25 deletions
|
@ -9,7 +9,7 @@ for i in *.toml; do
|
|||
echo " [FAILED]"
|
||||
fi
|
||||
else
|
||||
echo " [??]"
|
||||
echo " [?????]"
|
||||
fi
|
||||
|
||||
done
|
||||
|
|
3
stdex/bool1.toml
Normal file
3
stdex/bool1.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
bool1 = true
|
||||
bool2 = false
|
||||
|
4
stdex/bool1.toml.res
Normal file
4
stdex/bool1.toml.res
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
bool1 = true,
|
||||
bool2 = false,
|
||||
}
|
13
stdex/float1.toml
Normal file
13
stdex/float1.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
# fractional
|
||||
flt1 = +1.0
|
||||
flt2 = 3.1415
|
||||
flt3 = -0.01
|
||||
|
||||
# exponent
|
||||
flt4 = 5e+22
|
||||
flt5 = 1e06
|
||||
flt6 = -2E-2
|
||||
|
||||
# both
|
||||
flt7 = 6.626e-34
|
||||
|
9
stdex/float1.toml.res
Normal file
9
stdex/float1.toml.res
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
flt1 = 1.000000,
|
||||
flt2 = 3.141500,
|
||||
flt3 = -0.010000,
|
||||
flt4 = 49999999999999995805696.000000,
|
||||
flt5 = 1000000.000000,
|
||||
flt6 = -0.020000,
|
||||
flt7 = 0.000000,
|
||||
}
|
1
stdex/float2.toml
Normal file
1
stdex/float2.toml
Normal file
|
@ -0,0 +1 @@
|
|||
invalid_float_1 = .7
|
2
stdex/float2.toml.res
Normal file
2
stdex/float2.toml.res
Normal file
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
ERROR: unable to decode value in table
|
2
stdex/float3.toml
Normal file
2
stdex/float3.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
invalid_float_2 = 7.
|
||||
|
2
stdex/float3.toml.res
Normal file
2
stdex/float3.toml.res
Normal file
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
ERROR: unable to decode value in table
|
1
stdex/float4.toml
Normal file
1
stdex/float4.toml
Normal file
|
@ -0,0 +1 @@
|
|||
invalid_float_3 = 3.e+20
|
2
stdex/float4.toml.res
Normal file
2
stdex/float4.toml.res
Normal file
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
ERROR: unable to decode value in table
|
1
stdex/float5.toml
Normal file
1
stdex/float5.toml
Normal file
|
@ -0,0 +1 @@
|
|||
flt8 = 224_617.445_991_228
|
3
stdex/float5.toml.res
Normal file
3
stdex/float5.toml.res
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
flt8 = 224617.445991,
|
||||
}
|
10
stdex/float6.toml
Normal file
10
stdex/float6.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
# infinity
|
||||
sf1 = inf # positive infinity
|
||||
sf2 = +inf # positive infinity
|
||||
sf3 = -inf # negative infinity
|
||||
|
||||
# not a number
|
||||
sf4 = nan # actual sNaN/qNaN encoding is implementation-specific
|
||||
sf5 = +nan # same as `nan`
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific
|
||||
|
8
stdex/float6.toml.res
Normal file
8
stdex/float6.toml.res
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
sf1 = inf,
|
||||
sf2 = inf,
|
||||
sf3 = -inf,
|
||||
sf4 = nan,
|
||||
sf5 = nan,
|
||||
sf6 = nan,
|
||||
}
|
9
stdex/int0.toml
Normal file
9
stdex/int0.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
int1 = +99
|
||||
int2 = 42
|
||||
int3 = 0
|
||||
int4 = -17
|
||||
int5 = 1_000
|
||||
int6 = 5_349_221
|
||||
int7 = 53_49_221 # Indian number system grouping
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged
|
||||
|
10
stdex/int0.toml.res
Normal file
10
stdex/int0.toml.res
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
int1 = 99,
|
||||
int2 = 42,
|
||||
int3 = 0,
|
||||
int4 = -17,
|
||||
int5 = 1000,
|
||||
int6 = 5349221,
|
||||
int7 = 5349221,
|
||||
int8 = 12345,
|
||||
}
|
12
stdex/int1.toml
Normal file
12
stdex/int1.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
# hexadecimal with prefix `0x`
|
||||
hex1 = 0xDEADBEEF
|
||||
hex2 = 0xdeadbeef
|
||||
hex3 = 0xdead_beef
|
||||
|
||||
# octal with prefix `0o`
|
||||
oct1 = 0o01234567
|
||||
oct2 = 0o755 # useful for Unix file permissions
|
||||
|
||||
# binary with prefix `0b`
|
||||
bin1 = 0b11010110
|
||||
|
8
stdex/int1.toml.res
Normal file
8
stdex/int1.toml.res
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
hex1 = 3735928559,
|
||||
hex2 = 3735928559,
|
||||
hex3 = 3735928559,
|
||||
oct1 = 342391,
|
||||
oct2 = 493,
|
||||
bin1 = 214,
|
||||
}
|
4
stdex/ts1.toml
Normal file
4
stdex/ts1.toml
Normal file
|
@ -0,0 +1,4 @@
|
|||
odt1 = 1979-05-27T07:32:00Z
|
||||
odt2 = 1979-05-27T00:32:00-07:00
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00
|
||||
|
5
stdex/ts1.toml.res
Normal file
5
stdex/ts1.toml.res
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
odt1 = 1979-05-27T07:32:00Z,
|
||||
odt2 = 1979-05-27T00:32:00-07:00,
|
||||
odt3 = 1979-05-27T00:32:00.999-07:00,
|
||||
}
|
1
stdex/ts2.toml
Normal file
1
stdex/ts2.toml
Normal file
|
@ -0,0 +1 @@
|
|||
odt4 = 1979-05-27 07:32:00Z
|
3
stdex/ts2.toml.res
Normal file
3
stdex/ts2.toml.res
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
odt4 = 1979-05-27T07:32:00Z,
|
||||
}
|
2
stdex/ts3.toml
Normal file
2
stdex/ts3.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
ldt1 = 1979-05-27T07:32:00
|
||||
ldt2 = 1979-05-27T00:32:00.999999
|
4
stdex/ts3.toml.res
Normal file
4
stdex/ts3.toml.res
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
ldt1 = 1979-05-27T07:32:00,
|
||||
ldt2 = 1979-05-27T00:32:00.999,
|
||||
}
|
1
stdex/ts4.toml
Normal file
1
stdex/ts4.toml
Normal file
|
@ -0,0 +1 @@
|
|||
ld1 = 1979-05-27
|
3
stdex/ts4.toml.res
Normal file
3
stdex/ts4.toml.res
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
ld1 = 1979-05-27,
|
||||
}
|
2
stdex/ts5.toml
Normal file
2
stdex/ts5.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
lt1 = 07:32:00
|
||||
lt2 = 00:32:00.999999
|
4
stdex/ts5.toml.res
Normal file
4
stdex/ts5.toml.res
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
lt1 = 07:32:00,
|
||||
lt2 = 00:32:00.999,
|
||||
}
|
42
toml.c
42
toml.c
|
@ -2073,9 +2073,14 @@ int toml_rtod_ex(toml_raw_t src, double* ret_, char* buf, int buflen)
|
|||
if (s[0] == '_')
|
||||
return -1;
|
||||
|
||||
/* disallow +.99 */
|
||||
if (s[0] == '.')
|
||||
/* decimal point, if used, must be surrounded by at least one digit on each side */
|
||||
{
|
||||
char* dot = strchr(s, '.');
|
||||
if (dot) {
|
||||
if (dot == s || !isdigit(dot[-1]) || !isdigit(dot[1]))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* zero must be followed by . or 'e', or NUL */
|
||||
if (s[0] == '0' && s[1] && !strchr("eE.", s[1]))
|
||||
|
@ -2084,28 +2089,17 @@ int toml_rtod_ex(toml_raw_t src, double* ret_, char* buf, int buflen)
|
|||
/* just strip underscores and pass to strtod */
|
||||
while (*s && p < q) {
|
||||
int ch = *s++;
|
||||
switch (ch) {
|
||||
case '.':
|
||||
if (s[-2] == '_') return -1;
|
||||
if (s[0] == '_') return -1;
|
||||
break;
|
||||
case '_':
|
||||
if (ch == '_') {
|
||||
// disallow '__'
|
||||
if (s[0] == '_') return -1;
|
||||
// disallow last char '_'
|
||||
if (s[0] == 0) return -1;
|
||||
continue; /* skip _ */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*p++ = ch;
|
||||
}
|
||||
if (*s || p == q) return -1; /* reached end of string or buffer is full? */
|
||||
|
||||
/* last char cannot be '_' */
|
||||
if (s[-1] == '_') return -1;
|
||||
|
||||
if (p != buf && p[-1] == '.')
|
||||
return -1; /* no trailing zero */
|
||||
|
||||
/* cap with NUL */
|
||||
*p = 0;
|
||||
|
||||
|
@ -2219,6 +2213,14 @@ toml_datum_t toml_timestamp_at(const toml_array_t* arr, int idx)
|
|||
ret.ok = !!(ret.u.ts = malloc(sizeof(*ret.u.ts)));
|
||||
if (ret.ok) {
|
||||
*ret.u.ts = ts;
|
||||
if (ret.u.ts->year) ret.u.ts->year = &ret.u.ts->__buffer.year;
|
||||
if (ret.u.ts->month) ret.u.ts->month = &ret.u.ts->__buffer.month;
|
||||
if (ret.u.ts->day) ret.u.ts->day = &ret.u.ts->__buffer.day;
|
||||
if (ret.u.ts->hour) ret.u.ts->hour = &ret.u.ts->__buffer.hour;
|
||||
if (ret.u.ts->minute) ret.u.ts->minute = &ret.u.ts->__buffer.minute;
|
||||
if (ret.u.ts->second) ret.u.ts->second = &ret.u.ts->__buffer.second;
|
||||
if (ret.u.ts->millisec) ret.u.ts->millisec = &ret.u.ts->__buffer.millisec;
|
||||
if (ret.u.ts->z) ret.u.ts->z = ret.u.ts->__buffer.z;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -2269,6 +2271,14 @@ toml_datum_t toml_timestamp_in(const toml_table_t* arr, const char* key)
|
|||
ret.ok = !!(ret.u.ts = malloc(sizeof(*ret.u.ts)));
|
||||
if (ret.ok) {
|
||||
*ret.u.ts = ts;
|
||||
if (ret.u.ts->year) ret.u.ts->year = &ret.u.ts->__buffer.year;
|
||||
if (ret.u.ts->month) ret.u.ts->month = &ret.u.ts->__buffer.month;
|
||||
if (ret.u.ts->day) ret.u.ts->day = &ret.u.ts->__buffer.day;
|
||||
if (ret.u.ts->hour) ret.u.ts->hour = &ret.u.ts->__buffer.hour;
|
||||
if (ret.u.ts->minute) ret.u.ts->minute = &ret.u.ts->__buffer.minute;
|
||||
if (ret.u.ts->second) ret.u.ts->second = &ret.u.ts->__buffer.second;
|
||||
if (ret.u.ts->millisec) ret.u.ts->millisec = &ret.u.ts->__buffer.millisec;
|
||||
if (ret.u.ts->z) ret.u.ts->z = ret.u.ts->__buffer.z;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
43
toml_cat.c
43
toml_cat.c
|
@ -157,19 +157,35 @@ static void print_table(toml_table_t* curtab)
|
|||
d = toml_double_in(curtab, key);
|
||||
if (d.ok) {
|
||||
prindent();
|
||||
printf("%s = %g,\n", key, d.u.d);
|
||||
printf("%s = %f,\n", key, d.u.d);
|
||||
continue;
|
||||
}
|
||||
|
||||
d = toml_timestamp_in(curtab, key);
|
||||
if (d.ok) {
|
||||
prindent();
|
||||
printf(" %s = %s,\n", key, toml_raw_in(curtab, key));
|
||||
printf("%s = ", key);
|
||||
if (d.u.ts->year) {
|
||||
printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,
|
||||
d.u.ts->hour ? "T" : "");
|
||||
}
|
||||
if (d.u.ts->hour) {
|
||||
printf("%02d:%02d:%02d", *d.u.ts->hour, *d.u.ts->minute, *d.u.ts->second);
|
||||
if (d.u.ts->millisec) {
|
||||
printf(".%d", *d.u.ts->millisec);
|
||||
}
|
||||
if (d.u.ts->z) {
|
||||
printf("%s", d.u.ts->z);
|
||||
}
|
||||
}
|
||||
printf(",\n");
|
||||
free(d.u.ts);
|
||||
continue;
|
||||
}
|
||||
|
||||
abort();
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "ERROR: unable to decode value in table\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,19 +247,34 @@ static void print_array(toml_array_t* curarr)
|
|||
d = toml_double_at(curarr, i);
|
||||
if (d.ok) {
|
||||
prindent();
|
||||
printf("%g,\n", d.u.d);
|
||||
printf("%f,\n", d.u.d);
|
||||
continue;
|
||||
}
|
||||
|
||||
d = toml_timestamp_at(curarr, i);
|
||||
if (d.ok) {
|
||||
prindent();
|
||||
printf("%s,\n", toml_raw_at(curarr, i));
|
||||
if (d.u.ts->year) {
|
||||
printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,
|
||||
d.u.ts->hour ? "T" : "");
|
||||
}
|
||||
if (d.u.ts->hour) {
|
||||
printf("%02d:%02d:%02d", *d.u.ts->hour, *d.u.ts->minute, *d.u.ts->second);
|
||||
if (d.u.ts->millisec) {
|
||||
printf(".%d", *d.u.ts->millisec);
|
||||
}
|
||||
if (d.u.ts->z) {
|
||||
printf("%s", d.u.ts->z);
|
||||
}
|
||||
}
|
||||
printf(",\n");
|
||||
free(d.u.ts);
|
||||
continue;
|
||||
}
|
||||
|
||||
abort();
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "ERROR: unable to decode value in array\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue