feat: local date-time, offset date-time, local time, local date support (reading to string)

This commit is contained in:
MihailRis 2024-10-13 10:51:24 +03:00
parent 9667b81438
commit 68c3a646c8
2 changed files with 18 additions and 9 deletions

View File

@ -76,17 +76,26 @@ class TomlReader : BasicParser {
dv::value parseValue() {
char c = peek();
if (is_digit(c)) {
return parseNumber(1);
int start = pos;
// parse numeric literal
auto value = parseNumber(1);
if (hasNext() && peekNoJump() == '-') {
while (hasNext()) {
c = source[pos];
if (!is_digit(c) && c != ':' && c != '.' && c != '-' &&
c != 'T' && c != 'Z') {
break;
}
pos++;
}
return std::string(source.substr(start, pos - start));
}
return value;
} else if (c == '-' || c == '+') {
int sign = c == '-' ? -1 : 1;
pos++;
// parse numeric literal
auto value = parseNumber(sign);
if (hasNext() && peekNoJump() == '-') {
// parse timestamp // TODO: implement
throw error("timestamps support is not implemented yet");
}
return value;
return parseNumber(sign);
} else if (is_identifier_start(c)) {
// parse keywords
std::string keyword = parseName();
@ -178,7 +187,7 @@ class TomlReader : BasicParser {
dv::value& lvalue = parseLValue(map);
expect('=');
lvalue = parseValue();
skipWhitespace();
expectNewLine();
}
}
public:

View File

@ -57,7 +57,7 @@ inline std::string SRC_EXAMPLE =
"\n"
"[owner]\n"
"name = \"Tom Preston-Werner\"\n"
// "dob = 1979-05-27T07:32:00-08:00\n"
"dob = 1979-05-27T07:32:00-08:00\n"
"\n"
"[database]\n"
"enabled = true\n"