| 14545 | TOML_NODISCARD |
| 14546 | TOML_NEVER_INLINE |
| 14547 | date_time parse_date_time() |
| 14548 | { |
| 14549 | return_if_error({}); |
| 14550 | assert_not_eof(); |
| 14551 | TOML_ASSERT_ASSUME(is_decimal_digit(*cp)); |
| 14552 | push_parse_scope("date-time"sv); |
| 14553 | |
| 14554 | // "YYYY-MM-DD" |
| 14555 | auto date = parse_date(true); |
| 14556 | set_error_and_return_if_eof({}); |
| 14557 | |
| 14558 | // ' ', 'T' or 't' |
| 14559 | if (!is_match(*cp, U' ', U'T', U't')) |
| 14560 | set_error_and_return_default("expected space, 'T' or 't', saw '"sv, to_sv(*cp), "'"sv); |
| 14561 | advance_and_return_if_error_or_eof({}); |
| 14562 | |
| 14563 | // "HH:MM:SS.FFFFFFFFF" |
| 14564 | auto time = parse_time(true); |
| 14565 | return_if_error({}); |
| 14566 | |
| 14567 | // no offset |
| 14568 | if (is_eof() || is_value_terminator(*cp)) |
| 14569 | return { date, time }; |
| 14570 | |
| 14571 | // zero offset ('Z' or 'z') |
| 14572 | time_offset offset{}; |
| 14573 | if (is_match(*cp, U'Z', U'z')) |
| 14574 | advance_and_return_if_error({}); |
| 14575 | |
| 14576 | // explicit offset ("+/-HH:MM") |
| 14577 | else if (is_match(*cp, U'+', U'-')) |
| 14578 | { |
| 14579 | push_parse_scope("date-time offset"sv); |
| 14580 | |
| 14581 | // sign |
| 14582 | int sign = *cp == U'-' ? -1 : 1; |
| 14583 | advance_and_return_if_error_or_eof({}); |
| 14584 | |
| 14585 | // "HH" |
| 14586 | int digits[2]; |
| 14587 | if (!consume_digit_sequence(digits, 2u)) |
| 14588 | set_error_and_return_default("expected 2-digit hour, saw '"sv, to_sv(cp), "'"sv); |
| 14589 | const auto hour = digits[1] + digits[0] * 10; |
| 14590 | if (hour > 23) |
| 14591 | set_error_and_return_default("expected hour between 0 and 23 (inclusive), saw "sv, hour); |
| 14592 | set_error_and_return_if_eof({}); |
| 14593 | |
| 14594 | // ':' |
| 14595 | if (*cp != U':') |
| 14596 | set_error_and_return_default("expected ':', saw '"sv, to_sv(*cp), "'"sv); |
| 14597 | advance_and_return_if_error_or_eof({}); |
| 14598 | |
| 14599 | // "MM" |
| 14600 | if (!consume_digit_sequence(digits, 2u)) |
| 14601 | set_error_and_return_default("expected 2-digit minute, saw '"sv, to_sv(cp), "'"sv); |
| 14602 | const auto minute = digits[1] + digits[0] * 10; |
| 14603 | if (minute > 59) |
| 14604 | set_error_and_return_default("expected minute between 0 and 59 (inclusive), saw "sv, minute); |
nothing calls this directly
no outgoing calls
no test coverage detected