LCOV - code coverage report
Current view: top level - util - misc.cpp (source / functions) Hit Total Coverage
Test: gjs- Code Coverage Lines: 14 17 82.4 %
Date: 2023-09-17 02:39:54 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 10 70.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :            : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :            : // SPDX-FileCopyrightText: 2008 litl, LLC
       4                 :            : 
       5                 :            : #include <glib.h>
       6                 :            : 
       7                 :            : #include "util/misc.h"
       8                 :            : 
       9                 :            : bool
      10                 :        484 : gjs_environment_variable_is_set(const char *env_variable_name)
      11                 :            : {
      12                 :            :     const char *s;
      13                 :            : 
      14                 :        484 :     s = g_getenv(env_variable_name);
      15         [ +  - ]:        484 :     if (!s)
      16                 :        484 :         return false;
      17                 :            : 
      18         [ #  # ]:          0 :     if (*s == '\0')
      19                 :          0 :         return false;
      20                 :            : 
      21                 :          0 :     return true;
      22                 :            : }
      23                 :            : 
      24                 :            : /** gjs_g_strv_concat:
      25                 :            :  *
      26                 :            :  * Concate an array of string arrays to one string array. The strings in each
      27                 :            :  * array is copied to the resulting array.
      28                 :            :  *
      29                 :            :  * @strv_array: array of 0-terminated arrays of strings. Null elements are
      30                 :            :  * allowed.
      31                 :            :  * @len: number of arrays in @strv_array
      32                 :            :  *
      33                 :            :  * Returns: (transfer full): a newly allocated 0-terminated array of strings.
      34                 :            :  */
      35                 :          2 : char** gjs_g_strv_concat(char*** strv_array, int len) {
      36                 :          2 :     GPtrArray* array = g_ptr_array_sized_new(16);
      37                 :            : 
      38         [ +  + ]:          6 :     for (int i = 0; i < len; i++) {
      39                 :          4 :         char** strv = strv_array[i];
      40         [ +  + ]:          4 :         if (!strv)
      41                 :          1 :             continue;
      42                 :            : 
      43         [ +  + ]:          5 :         for (int j = 0; strv[j]; ++j)
      44                 :          4 :             g_ptr_array_add(array, g_strdup(strv[j]));
      45                 :            :     }
      46                 :            : 
      47                 :          2 :     g_ptr_array_add(array, nullptr);
      48                 :            : 
      49                 :          2 :     return reinterpret_cast<char**>(g_ptr_array_free(array, false));
      50                 :            : }

Generated by: LCOV version 1.14