LCOV - code coverage report
Current view: top level - src - string_view.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 14 14 100.0 %
Date: 2026-11-26 02:32:31 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 10 100.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright 2007-2025 David Robillard <d@drobilla.net>
       2                 :            : // SPDX-License-Identifier: ISC
       3                 :            : 
       4                 :            : #include <zix/string_view.h>
       5                 :            : 
       6                 :            : #include <zix/allocator.h>
       7                 :            : #include <zix/attributes.h>
       8                 :            : 
       9                 :            : #include <stdbool.h>
      10                 :            : #include <string.h>
      11                 :            : 
      12                 :            : char*
      13                 :         64 : zix_string_view_copy(ZixAllocator* const allocator, const ZixStringView view)
      14                 :            : {
      15                 :         64 :   char* const copy = (char*)zix_malloc(allocator, view.length + 1U);
      16         [ +  + ]:         64 :   if (copy) {
      17                 :         60 :     memcpy(copy, view.data, view.length);
      18                 :         60 :     copy[view.length] = '\0';
      19                 :            :   }
      20                 :         64 :   return copy;
      21                 :            : }
      22                 :            : 
      23                 :            : ZIX_NONBLOCKING bool
      24                 :         13 : zix_string_view_equals(const ZixStringView lhs, const ZixStringView rhs)
      25                 :            : {
      26         [ +  + ]:         13 :   if (lhs.length != rhs.length) {
      27                 :          3 :     return false;
      28                 :            :   }
      29                 :            : 
      30         [ +  + ]:         10 :   if (lhs.data != rhs.data) {
      31         [ +  + ]:         32 :     for (size_t i = 0U; i < lhs.length; ++i) {
      32         [ +  + ]:         27 :       if (lhs.data[i] != rhs.data[i]) {
      33                 :          3 :         return false;
      34                 :            :       }
      35                 :            :     }
      36                 :            :   }
      37                 :            : 
      38                 :          7 :   return true;
      39                 :            : }

Generated by: LCOV version 1.16