| 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
| Branch | True | False | Total |
| for(i = 0; i < n; i++){ |
155 |
9 |
164 |
|
| 20 |
155 |
▶ | if(x[i] != y[i]){ |
Branch: 1 branch
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| if(x[i] != y[i]){ |
76 |
104 |
180 |
|
| 33 |
76 |
| return 0; |
| 34 |
|
| } |
| 35 |
104 |
▶ | else if(x[i] == '\0'){ |
Branch: 1 branch
| Branch | True | False | Total |
| 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 */ |