NeoMutt  2025-09-05-43-g177ed6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
eqi.h
Go to the documentation of this file.
1
22
42
43#ifndef MUTT_MUTT_EQI_H
44#define MUTT_MUTT_EQI_H
45
46#include <stdbool.h>
47#include <stdint.h>
48#include <string.h>
49
65static inline uint64_t make_lowercase_mask(uint64_t x, int bytenum)
66{
67 const char ch = x >> (bytenum * 8);
68 const uint64_t mask = ((ch >= 'a') && (ch <= 'z')) ? 0x20 : 0;
69 return mask << (bytenum * 8);
70}
71
78static inline bool eqi1(const char *a, const char b[1])
79{
80 uint8_t b8 = b[0];
81 return (*a | make_lowercase_mask(b8, 0)) == (unsigned char) b[0];
82}
83
90static inline bool eqi2(const char *a, const char b[2])
91{
92 uint16_t a16, b16;
93 memcpy(&a16, a, sizeof(a16));
94 memcpy(&b16, b, sizeof(b16));
95 const uint16_t lowercase_mask = make_lowercase_mask(b16, 0) |
96 make_lowercase_mask(b16, 1);
97 return (a16 | lowercase_mask) == b16;
98}
99
106static inline bool eqi4(const char *a, const char b[4])
107{
108 uint32_t a32, b32;
109 memcpy(&a32, a, sizeof(a32));
110 memcpy(&b32, b, sizeof(b32));
111 const uint32_t lowercase_mask = make_lowercase_mask(b32, 0) |
112 make_lowercase_mask(b32, 1) |
113 make_lowercase_mask(b32, 2) |
114 make_lowercase_mask(b32, 3);
115 return (a32 | lowercase_mask) == b32;
116}
117
124static inline bool eqi8(const char *a, const char b[8])
125{
126 uint64_t a64, b64;
127 memcpy(&a64, a, sizeof(a64));
128 memcpy(&b64, b, sizeof(b64));
129 const uint64_t lowercase_mask = make_lowercase_mask(b64, 0) |
130 make_lowercase_mask(b64, 1) |
131 make_lowercase_mask(b64, 2) |
132 make_lowercase_mask(b64, 3) |
133 make_lowercase_mask(b64, 4) |
134 make_lowercase_mask(b64, 5) |
135 make_lowercase_mask(b64, 6) |
136 make_lowercase_mask(b64, 7);
137 return (a64 | lowercase_mask) == b64;
138}
139
140/* various helpers for increased readability */
141
142/* there's no eqi3(); consider using eqi4() instead if you can */
143
145static inline bool eqi5(const char *a, const char b[5])
146{
147 return eqi4(a, b) && eqi1(a + 1, b + 1);
148}
149
151static inline bool eqi6(const char *a, const char b[6])
152{
153 return eqi4(a, b) && eqi2(a + 4, b + 4);
154}
155
156/* there's no eqi7(); consider using eqi8() instead if you can */
157
159static inline bool eqi9(const char *a, const char b[9])
160{
161 return eqi8(a, b) && eqi1(a + 8, b + 8);
162}
163
165static inline bool eqi10(const char *a, const char b[10])
166{
167 return eqi8(a, b) && eqi2(a + 8, b + 8);
168}
169
171static inline bool eqi11(const char *a, const char b[11])
172{
173 return eqi8(a, b) && eqi4(a + 7, b + 7);
174}
175
177static inline bool eqi12(const char *a, const char b[12])
178{
179 return eqi8(a, b) && eqi4(a + 8, b + 8);
180}
181
183static inline bool eqi13(const char *a, const char b[13])
184{
185 return eqi8(a, b) && eqi8(a + 5, b + 5);
186}
187
189static inline bool eqi14(const char *a, const char b[14])
190{
191 return eqi8(a, b) && eqi8(a + 6, b + 6);
192}
193
195static inline bool eqi15(const char *a, const char b[15])
196{
197 return eqi8(a, b) && eqi8(a + 7, b + 7);
198}
199
201static inline bool eqi16(const char *a, const char b[16])
202{
203 return eqi8(a, b) && eqi8(a + 8, b + 8);
204}
205
207static inline bool eqi17(const char *a, const char b[17])
208{
209 return eqi16(a, b) && eqi1(a + 16, b + 16);
210}
211
212#endif /* MUTT_MUTT_EQI_H */
static bool eqi17(const char *a, const char b[17])
eqi17 - Compare two 17-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:207
static bool eqi9(const char *a, const char b[9])
eqi9 - Compare two 9-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:159
static bool eqi10(const char *a, const char b[10])
eqi10 - Compare two 10-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:165
static bool eqi8(const char *a, const char b[8])
Compare two 8-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons.
Definition eqi.h:124
static bool eqi11(const char *a, const char b[11])
eqi11 - Compare two 11-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:171
static bool eqi6(const char *a, const char b[6])
eqi6 - Compare two 6-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:151
static bool eqi14(const char *a, const char b[14])
eqi14 - Compare two 14-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:189
static bool eqi13(const char *a, const char b[13])
eqi13 - Compare two 13-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:183
static bool eqi4(const char *a, const char b[4])
Compare two 4-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons.
Definition eqi.h:106
static uint64_t make_lowercase_mask(uint64_t x, int bytenum)
Create a mask to lowercase alphabetic characters.
Definition eqi.h:65
static bool eqi5(const char *a, const char b[5])
eqi5 - Compare two 5-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:145
static bool eqi12(const char *a, const char b[12])
eqi12 - Compare two 12-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:177
static bool eqi16(const char *a, const char b[16])
eqi16 - Compare two 16-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:201
static bool eqi15(const char *a, const char b[15])
eqi15 - Compare two 15-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons
Definition eqi.h:195
static bool eqi1(const char *a, const char b[1])
Compare two 1-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons.
Definition eqi.h:78
static bool eqi2(const char *a, const char b[2])
Compare two 2-byte strings, ignoring case - See: Case-insensitive fixed-chunk comparisons.
Definition eqi.h:90