LCOV - code coverage report
Current view: top level - src - month_day.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 22 22 100.0 %
Date: 2026-08-20 23:47:58 Functions: 2 2 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 "timezone.h"
       9                 :            : #include "write_utils.h"
      10                 :            : 
      11                 :            : #include <exess/exess.h>
      12                 :            : 
      13                 :            : #include <string.h>
      14                 :            : 
      15                 :            : EXESS_NONBLOCKING ExessResult
      16                 :         42 : exess_read_month_day(const char* const str, ExessMonthDay* const out)
      17                 :            : {
      18                 :         42 :   memset(out, 0, sizeof(*out));
      19                 :            : 
      20                 :            :   // Skip leading absent-year delimiter
      21                 :         42 :   size_t i = skip_whitespace(str);
      22         [ +  + ]:         42 :   if (str[i] != '-') {
      23                 :          5 :     return RESULT(EXESS_EXPECTED_DASH, i);
      24                 :            :   }
      25                 :            : 
      26                 :            :   // Read (leading month delimiter and) month
      27                 :         37 :   ++i;
      28                 :         37 :   ExessResult r = read_date_m(&out->month, str + i);
      29                 :         37 :   i += r.count;
      30                 :            : 
      31         [ +  + ]:         37 :   if (!r.status) {
      32                 :            :     // Read (month-day delimiter and) day
      33                 :         33 :     r = read_date_d(&out->day, str + i);
      34                 :            :   }
      35                 :            : 
      36                 :            :   // Read timezone if present
      37                 :         37 :   r.count = i + r.count;
      38                 :         37 :   return read_optional_timezone(&out->zone, str, r);
      39                 :            : }
      40                 :            : 
      41                 :            : EXESS_NONBLOCKING ExessResult
      42                 :         29 : exess_write_month_day(const ExessMonthDay value,
      43                 :            :                       const size_t        buf_size,
      44                 :            :                       char* const         buf)
      45                 :            : {
      46   [ +  +  +  +  :         29 :   if (value.month < 1 || value.month > 12 || value.day < 1 || value.day > 31) {
             +  +  +  + ]
      47                 :          4 :     return end_write(EXESS_BAD_VALUE, buf_size, buf, 0);
      48                 :            :   }
      49                 :            : 
      50                 :            :   // Write --MM-DD numbers
      51                 :         25 :   ExessResult r = {EXESS_SUCCESS, 0};
      52                 :         25 :   r.count += write_char('-', buf_size, buf, r.count);
      53                 :         25 :   r.count += write_char('-', buf_size, buf, r.count);
      54                 :         25 :   r.count += write_two_digit_number(value.month, buf_size, buf, r.count);
      55                 :         25 :   r.count += write_char('-', buf_size, buf, r.count);
      56                 :         25 :   r.count += write_two_digit_number(value.day, buf_size, buf, r.count);
      57                 :            : 
      58                 :            :   // Write timezone suffix and end write
      59                 :         25 :   return write_timezone(value.zone, buf_size, buf, r);
      60                 :            : }

Generated by: LCOV version 1.16