• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipse-bluechi / bluechi / 17201662698

25 Aug 2025 07:01AM UTC coverage: 20.522% (-62.2%) from 82.723%
17201662698

Pull #1094

github

web-flow
Merge 9390aa731 into 3c2c3a81a
Pull Request #1094: Add coverage improvements and version handling

1022 of 4980 relevant lines covered (20.52%)

11.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.12
/src/libbluechi/common/string-util.h
1
/*
2
 * Copyright Contributors to the Eclipse BlueChi project
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
#pragma once
7

8
#include <stdarg.h>
9
#include <stdbool.h>
10
#include <stdlib.h>
11
#include <string.h>
12

13
/* Constants */
14
#define SYMBOL_WILDCARD "*"
15
#define SYMBOL_GLOB_ALL '*'
16
#define SYMBOL_GLOB_ONE '?'
17

18
#define streq(a, b) (strcmp((a), (b)) == 0)
19
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
20

21
#define streqi(a, b) (strcasecmp(a, b) == 0)
22
#define strneqi(a, b, n) (strncasecmp(a, b, n) == 0)
23

24
#define bool_to_str(b) b ? "true" : "false"
25

26
static inline bool ascii_isdigit(char a) {
272✔
27
        return a >= '0' && a <= '9';
272✔
28
}
29

30
static inline bool ascii_isalpha(char a) {
285✔
31
        return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z');
285✔
32
}
33

34
static inline char *strcat_dup(const char *a, const char *b) {
2✔
35
        size_t a_len = strlen(a);
2✔
36
        size_t b_len = strlen(b);
2✔
37
        size_t len = a_len + b_len + 1;
2✔
38
        char *res = malloc(len);
2✔
39
        if (res) {
2✔
40
                memcpy(res, a, a_len);
2✔
41
                memcpy(res + a_len, b, b_len);
2✔
42
                res[a_len + b_len] = 0;
2✔
43
        }
44

45
        return res;
2✔
46
}
47

48
static inline bool copy_str(char **p, const char *s) {
4✔
49
        char *dup = strdup(s);
4✔
50
        if (dup == NULL) {
4✔
51
                return false;
52
        }
53
        free(*p);
4✔
54
        *p = dup;
4✔
55
        return true;
4✔
56
}
57

58
static inline bool is_wildcard(const char *in) {
×
59
        return streq(in, SYMBOL_WILDCARD);
×
60
}
61

62
static inline bool is_glob(const char *s) {
12✔
63
        return s != NULL && (strchr(s, SYMBOL_GLOB_ALL) != NULL || strchr(s, SYMBOL_GLOB_ONE) != NULL);
12✔
64
}
65

66
static inline bool str_has_prefix(const char *s, const char *prefix) {
4✔
67
        return strncmp(s, prefix, strlen(prefix)) == 0;
4✔
68
}
69

70
// NOLINTBEGIN(misc-no-recursion)
71
static inline bool match_glob(const char *str, const char *glob) {
280✔
72
        if (str == NULL || glob == NULL) {
280✔
73
                return false;
74
        }
75

76
        if (*glob == SYMBOL_GLOB_ALL) {
277✔
77
                return match_glob(str, glob + 1) || (*str && match_glob(str + 1, glob));
222✔
78
        }
79

80
        if (*str) {
166✔
81
                return ((SYMBOL_GLOB_ONE == *glob) || (*str == *glob)) && match_glob(str + 1, glob + 1);
268✔
82
        }
83

84
        return !*glob;
15✔
85
}
86
// NOLINTEND(misc-no-recursion)
87

88
static inline bool isempty(const char *a) {
15✔
89
        return !a || a[0] == '\0';
15✔
90
}
91

92
static inline bool ends_with(const char *str, const char *suffix) {
38✔
93
        if (str == NULL || suffix == NULL) {
38✔
94
                return false;
95
        }
96

97
        size_t str_length = strlen(str);
35✔
98
        size_t suffix_length = strlen(suffix);
35✔
99
        if (str_length < suffix_length) {
35✔
100
                return false;
101
        }
102
        return strncmp(str + str_length - suffix_length, suffix, suffix_length) == 0;
13✔
103
}
104

105
typedef struct StringBuilder StringBuilder;
106
struct StringBuilder {
107
        char *str;
108
        size_t len; /* Not including terminating zero */
109
        size_t capacity;
110
};
111

112
#define STRING_BUILDER_INIT { NULL, 0, 0 }
113
#define STRING_BUILDER_DEFAULT_CAPACITY 1024
114

115
bool string_builder_init(StringBuilder *builder, size_t initial_capacity);
116
void string_builder_destroy(StringBuilder *builder);
117
bool string_builder_append(StringBuilder *builder, const char *str);
118
bool string_builder_printf(StringBuilder *builder, const char *format, ...);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc