LCOV - code coverage report
Current view: top level - basic - strv.h (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 15 16 93.8 %
Date: 2019-08-22 15:41:25 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : #pragma once
       3             : 
       4             : #include <fnmatch.h>
       5             : #include <stdarg.h>
       6             : #include <stdbool.h>
       7             : #include <stddef.h>
       8             : #include <stdio.h>
       9             : 
      10             : #include "alloc-util.h"
      11             : #include "extract-word.h"
      12             : #include "hashmap.h"
      13             : #include "macro.h"
      14             : #include "string-util.h"
      15             : 
      16             : char *strv_find(char **l, const char *name) _pure_;
      17             : char *strv_find_prefix(char **l, const char *name) _pure_;
      18             : char *strv_find_startswith(char **l, const char *name) _pure_;
      19             : 
      20             : char **strv_free(char **l);
      21       21540 : DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
      22             : #define _cleanup_strv_free_ _cleanup_(strv_freep)
      23             : 
      24             : char **strv_free_erase(char **l);
      25           5 : DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase);
      26             : #define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep)
      27             : 
      28             : void strv_clear(char **l);
      29             : 
      30             : char **strv_copy(char * const *l);
      31             : size_t strv_length(char * const *l) _pure_;
      32             : 
      33             : int strv_extend_strv(char ***a, char **b, bool filter_duplicates);
      34             : int strv_extend_strv_concat(char ***a, char **b, const char *suffix);
      35             : int strv_extend(char ***l, const char *value);
      36             : int strv_extendf(char ***l, const char *format, ...) _printf_(2,0);
      37             : int strv_extend_front(char ***l, const char *value);
      38             : int strv_push(char ***l, char *value);
      39             : int strv_push_pair(char ***l, char *a, char *b);
      40             : int strv_insert(char ***l, size_t position, char *value);
      41             : 
      42           2 : static inline int strv_push_prepend(char ***l, char *value) {
      43           2 :         return strv_insert(l, 0, value);
      44             : }
      45             : 
      46             : int strv_consume(char ***l, char *value);
      47             : int strv_consume_pair(char ***l, char *a, char *b);
      48             : int strv_consume_prepend(char ***l, char *value);
      49             : 
      50             : char **strv_remove(char **l, const char *s);
      51             : char **strv_uniq(char **l);
      52             : bool strv_is_uniq(char **l);
      53             : 
      54             : bool strv_equal(char **a, char **b);
      55             : 
      56             : #define strv_contains(l, s) (!!strv_find((l), (s)))
      57             : 
      58             : char **strv_new_internal(const char *x, ...) _sentinel_;
      59             : char **strv_new_ap(const char *x, va_list ap);
      60             : #define strv_new(...) strv_new_internal(__VA_ARGS__, NULL)
      61             : 
      62             : #define STRV_IGNORE ((const char *) -1)
      63             : 
      64        2127 : static inline const char* STRV_IFNOTNULL(const char *x) {
      65        2127 :         return x ? x : STRV_IGNORE;
      66             : }
      67             : 
      68       15439 : static inline bool strv_isempty(char * const *l) {
      69       15439 :         return !l || !*l;
      70             : }
      71             : 
      72             : char **strv_split_full(const char *s, const char *separator, SplitFlags flags);
      73         170 : static inline char **strv_split(const char *s, const char *separator) {
      74         170 :         return strv_split_full(s, separator, 0);
      75             : }
      76             : char **strv_split_newlines(const char *s);
      77             : 
      78             : int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);
      79             : 
      80             : char *strv_join_prefix(char **l, const char *separator, const char *prefix);
      81         595 : static inline char *strv_join(char **l, const char *separator) {
      82         595 :         return strv_join_prefix(l, separator, NULL);
      83             : }
      84             : 
      85             : char **strv_parse_nulstr(const char *s, size_t l);
      86             : char **strv_split_nulstr(const char *s);
      87             : int strv_make_nulstr(char **l, char **p, size_t *n);
      88             : 
      89             : bool strv_overlap(char **a, char **b) _pure_;
      90             : 
      91             : #define STRV_FOREACH(s, l)                      \
      92             :         for ((s) = (l); (s) && *(s); (s)++)
      93             : 
      94             : #define STRV_FOREACH_BACKWARDS(s, l)                                \
      95             :         for (s = ({                                                 \
      96             :                         char **_l = l;                              \
      97             :                         _l ? _l + strv_length(_l) - 1U : NULL;      \
      98             :                         });                                         \
      99             :              (l) && ((s) >= (l));                                   \
     100             :              (s)--)
     101             : 
     102             : #define STRV_FOREACH_PAIR(x, y, l)               \
     103             :         for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))
     104             : 
     105             : char **strv_sort(char **l);
     106             : void strv_print(char **l);
     107             : 
     108             : #define STRV_MAKE(...) ((char**) ((const char*[]) { __VA_ARGS__, NULL }))
     109             : 
     110             : #define STRV_MAKE_EMPTY ((char*[1]) { NULL })
     111             : 
     112             : #define strv_from_stdarg_alloca(first)                          \
     113             :         ({                                                      \
     114             :                 char **_l;                                      \
     115             :                                                                 \
     116             :                 if (!first)                                     \
     117             :                         _l = (char**) &first;                   \
     118             :                 else {                                          \
     119             :                         size_t _n;                              \
     120             :                         va_list _ap;                            \
     121             :                                                                 \
     122             :                         _n = 1;                                 \
     123             :                         va_start(_ap, first);                   \
     124             :                         while (va_arg(_ap, char*))              \
     125             :                                 _n++;                           \
     126             :                         va_end(_ap);                            \
     127             :                                                                 \
     128             :                         _l = newa(char*, _n+1);                 \
     129             :                         _l[_n = 0] = (char*) first;             \
     130             :                         va_start(_ap, first);                   \
     131             :                         for (;;) {                              \
     132             :                                 _l[++_n] = va_arg(_ap, char*);  \
     133             :                                 if (!_l[_n])                    \
     134             :                                         break;                  \
     135             :                         }                                       \
     136             :                         va_end(_ap);                            \
     137             :                 }                                               \
     138             :                 _l;                                             \
     139             :         })
     140             : 
     141             : #define STR_IN_SET(x, ...) strv_contains(STRV_MAKE(__VA_ARGS__), x)
     142             : #define STRPTR_IN_SET(x, ...)                                    \
     143             :         ({                                                       \
     144             :                 const char* _x = (x);                            \
     145             :                 _x && strv_contains(STRV_MAKE(__VA_ARGS__), _x); \
     146             :         })
     147             : 
     148             : #define STARTSWITH_SET(p, ...)                                  \
     149             :         ({                                                      \
     150             :                 const char *_p = (p);                           \
     151             :                 char  *_found = NULL, **_i;                     \
     152             :                 STRV_FOREACH(_i, STRV_MAKE(__VA_ARGS__)) {      \
     153             :                         _found = startswith(_p, *_i);           \
     154             :                         if (_found)                             \
     155             :                                 break;                          \
     156             :                 }                                               \
     157             :                 _found;                                         \
     158             :         })
     159             : 
     160             : #define FOREACH_STRING(x, y, ...)                                       \
     161             :         for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__);        \
     162             :              x;                                                         \
     163             :              x = *(++_l))
     164             : 
     165             : char **strv_reverse(char **l);
     166             : char **strv_shell_escape(char **l, const char *bad);
     167             : 
     168             : bool strv_fnmatch(char* const* patterns, const char *s, int flags);
     169             : 
     170         530 : static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, int flags) {
     171         530 :         assert(s);
     172         530 :         return strv_isempty(patterns) ||
     173           0 :                strv_fnmatch(patterns, s, flags);
     174             : }
     175             : 
     176             : char ***strv_free_free(char ***l);
     177             : DEFINE_TRIVIAL_CLEANUP_FUNC(char***, strv_free_free);
     178             : 
     179             : char **strv_skip(char **l, size_t n);
     180             : 
     181             : int strv_extend_n(char ***l, const char *value, size_t n);
     182             : 
     183             : int fputstrv(FILE *f, char **l, const char *separator, bool *space);
     184             : 
     185             : #define strv_free_and_replace(a, b)             \
     186             :         ({                                      \
     187             :                 strv_free(a);                   \
     188             :                 (a) = (b);                      \
     189             :                 (b) = NULL;                     \
     190             :                 0;                              \
     191             :         })
     192             : 
     193             : extern const struct hash_ops string_strv_hash_ops;
     194             : int string_strv_hashmap_put(Hashmap **h, const char *key, const char *value);
     195             : int string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value);

Generated by: LCOV version 1.14