LCOV - code coverage report
Current view: top level - src - boolean.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 26 26 100.0 %
Date: 2026-07-14 21:28:07 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 11 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 "read_utils.h"
       5                 :            : #include "result.h"
       6                 :            : #include "write_utils.h"
       7                 :            : 
       8                 :            : #include <exess/exess.h>
       9                 :            : 
      10                 :            : #include <stdbool.h>
      11                 :            : #include <string.h>
      12                 :            : 
      13                 :            : EXESS_NONBLOCKING ExessResult
      14                 :         74 : exess_read_boolean(const char* const str, bool* const out)
      15                 :            : {
      16                 :         74 :   size_t      i = skip_whitespace(str);
      17                 :         74 :   ExessResult r = {EXESS_EXPECTED_BOOLEAN, i};
      18                 :            : 
      19                 :         74 :   *out = false;
      20                 :            : 
      21   [ +  +  +  +  :         74 :   switch (str[i]) {
                      + ]
      22                 :         13 :   case '0':
      23                 :         64 :     return RESULT(EXESS_SUCCESS, i + 1);
      24                 :            : 
      25                 :         12 :   case '1':
      26                 :         12 :     *out = true;
      27                 :         12 :     return RESULT(EXESS_SUCCESS, i + 1);
      28                 :            : 
      29                 :         27 :   case 't':
      30         [ +  + ]:         27 :     if (!strncmp(str + i, "true", 4)) {
      31                 :         25 :       *out = true;
      32                 :         25 :       return RESULT(EXESS_SUCCESS, i + 4U);
      33                 :            :     }
      34                 :          2 :     break;
      35                 :            : 
      36                 :         16 :   case 'f':
      37         [ +  + ]:         16 :     if (!strncmp(str + i, "false", 5)) {
      38                 :         14 :       return RESULT(EXESS_SUCCESS, i + 5U);
      39                 :            :     }
      40                 :          2 :     break;
      41                 :            : 
      42                 :          6 :   default:
      43                 :          6 :     break;
      44                 :            :   }
      45                 :            : 
      46                 :         10 :   return RESULT(r.status, r.count);
      47                 :            : }
      48                 :            : 
      49                 :            : EXESS_NONBLOCKING EXESS_NONBLOCKING ExessResult
      50                 :         30 : exess_write_boolean(const bool value, const size_t buf_size, char* const buf)
      51                 :            : {
      52         [ +  + ]:         60 :   return end_write(EXESS_SUCCESS,
      53                 :            :                    buf_size,
      54                 :            :                    buf,
      55                 :         20 :                    value ? write_string(4, "true", buf_size, buf, 0)
      56                 :         10 :                          : write_string(5, "false", buf_size, buf, 0));
      57                 :            : }

Generated by: LCOV version 1.16