LCOV - code coverage report
Current view: top level - src - year_month.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 13 13 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: 4 4 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 "timezone.h"
       8                 :            : #include "write_utils.h"
       9                 :            : #include "year.h"
      10                 :            : 
      11                 :            : #include <exess/exess.h>
      12                 :            : 
      13                 :            : #include <string.h>
      14                 :            : 
      15                 :            : EXESS_NONBLOCKING ExessResult
      16                 :         48 : exess_read_year_month(const char* const str, ExessYearMonth* const out)
      17                 :            : {
      18                 :         48 :   memset(out, 0, sizeof(*out));
      19                 :            : 
      20                 :            :   // Read YYYY-MM numbers
      21                 :         48 :   size_t      i = skip_whitespace(str);
      22                 :         48 :   ExessResult r = read_date_ym(&out->year, &out->month, str + i);
      23                 :            : 
      24                 :            :   // Read timezone if present
      25                 :         48 :   r.count = i + r.count;
      26                 :         48 :   return read_optional_timezone(&out->zone, str, r);
      27                 :            : }
      28                 :            : 
      29                 :            : EXESS_NONBLOCKING ExessResult
      30                 :         33 : exess_write_year_month(const ExessYearMonth value,
      31                 :            :                        const size_t         buf_size,
      32                 :            :                        char* const          buf)
      33                 :            : {
      34   [ +  +  +  + ]:         33 :   if (value.month < 1 || value.month > 12) {
      35                 :          2 :     return end_write(EXESS_BAD_VALUE, buf_size, buf, 0);
      36                 :            :   }
      37                 :            : 
      38                 :            :   // Write YYYY-MM numbers
      39                 :         31 :   ExessResult r = write_year_number(value.year, buf_size, buf);
      40                 :         31 :   r.count += write_char('-', buf_size, buf, r.count);
      41                 :         31 :   r.count += write_two_digit_number(value.month, buf_size, buf, r.count);
      42                 :            : 
      43                 :            :   // Write timezone suffix and end write
      44                 :         31 :   return write_timezone(value.zone, buf_size, buf, r);
      45                 :            : }

Generated by: LCOV version 1.16