LCOV - code coverage report
Current view: top level - src - date_utils.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 23 23 100.0 %
Date: 2026-07-14 21:28:07 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 12 100.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright 2019-2026 David Robillard <d@drobilla.net>
       2                 :            : // SPDX-License-Identifier: ISC
       3                 :            : 
       4                 :            : #include "date_utils.h"
       5                 :            : #include "number_utils.h"
       6                 :            : #include "read_utils.h"
       7                 :            : #include "result.h"
       8                 :            : #include "year.h"
       9                 :            : 
      10                 :            : #include <exess/exess.h>
      11                 :            : 
      12                 :            : #include <stddef.h>
      13                 :            : 
      14                 :            : EXESS_NONBLOCKING ExessResult
      15                 :        354 : read_date_numbers(ExessDate* const out, const char* const str)
      16                 :            : {
      17                 :            :   // Read year at the beginning
      18                 :        354 :   size_t      i = skip_whitespace(str);
      19                 :        354 :   ExessResult r = read_year_number(&out->year, str + i);
      20         [ +  + ]:        354 :   if (r.status) {
      21                 :         13 :     return RESULT(r.status, i + r.count);
      22                 :            :   }
      23                 :            : 
      24                 :            :   // Read year-month delimiter
      25                 :        341 :   i += r.count;
      26         [ +  + ]:        341 :   if (str[i] != '-') {
      27                 :          1 :     return RESULT(EXESS_EXPECTED_DASH, i);
      28                 :            :   }
      29                 :            : 
      30                 :            :   // Read month
      31                 :        340 :   ++i;
      32                 :        340 :   r = read_two_digit_number(&out->month, 1, 12, str + i);
      33         [ +  + ]:        340 :   if (r.status) {
      34                 :          3 :     return RESULT(r.status, i + r.count);
      35                 :            :   }
      36                 :            : 
      37                 :            :   // Read month-day delimiter
      38                 :        337 :   i += r.count;
      39         [ +  + ]:        337 :   if (str[i] != '-') {
      40                 :          1 :     return RESULT(EXESS_EXPECTED_DASH, i);
      41                 :            :   }
      42                 :            : 
      43                 :            :   // Read day
      44                 :        336 :   ++i;
      45                 :        336 :   r = read_two_digit_number(&out->day, 1, 31, str + i);
      46         [ +  + ]:        336 :   if (r.status) {
      47                 :          9 :     return RESULT(r.status, i + r.count);
      48                 :            :   }
      49                 :            : 
      50                 :            :   // Check that day is in range
      51                 :        327 :   i += r.count;
      52         [ +  + ]:        327 :   if (out->day > days_in_month(out->year, out->month)) {
      53                 :          5 :     return RESULT(EXESS_OUT_OF_RANGE, i);
      54                 :            :   }
      55                 :            : 
      56                 :        322 :   return RESULT(EXESS_SUCCESS, i);
      57                 :            : }

Generated by: LCOV version 1.16