streq.h

filter: Statementstmt 100% 11 / 11 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 19 / 19 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Instance.xs ↑ Summary
1 /*
2 * streq.h - Check string equality
3 *
4 * Provides: strEQ(a, b), strnEQ(a, b, n), strNE(a, b), strnNE(a, b, n)
5 *
6 */
7  
8 #ifndef INLINED_STR_EQ_H
9 #define INLINED_STR_EQ_H
10  
11 #if (!defined(__cplusplus__) || !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) && !defined(inline)
12 #define inline
13 #endif
14  
15 #undef strnEQ
16 static inline int
17 103 strnEQ(const char* const x, const char* const y, size_t const n){
18 register size_t i;
19 164 ▶ for(i = 0; i < n; i++){
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < n; i++){ 155 9 164
20 155 ▶ if(x[i] != y[i]){
Branch: 1 branch
BranchTrueFalseTotal
if(x[i] != y[i]){ 94 61 155
21 94 return 0;
22 }
23 }
24 9 return 1;
25 }
26  
27 #undef strEQ
28 static inline int
29 94 strEQ(const char* const x, const char* const y){
30 register size_t i;
31 180 for(i = 0; ; i++){
32 180 ▶ if(x[i] != y[i]){
Branch: 1 branch
BranchTrueFalseTotal
if(x[i] != y[i]){ 76 104 180
33 76 return 0;
34 }
35 104 ▶ else if(x[i] == '\0'){
Branch: 1 branch
BranchTrueFalseTotal
else if(x[i] == '\0'){ 18 86 104
36 18 return 1; /* y[i] is also '\0' */
37 }
38 }
39 return 1; /* not reached */
40 }
41  
42 #undef strnNE
43 #define strnNE(a, b, n) (!strnEQ(a, b, n))
44  
45 #undef strNE
46 #define strNE(a, b) (!strEQ(a, b))
47  
48 #endif /* !INLINED_STR_EQ_H */
« Instance.xs ↑ Summary