NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
eqi.h
Go to the documentation of this file.
1
41#ifndef MUTT_MUTT_EQI_H
42#define MUTT_MUTT_EQI_H
43
44#include <stdbool.h>
45#include <stdint.h>
46#include <string.h>
47
63static inline uint64_t make_lowercase_mask(uint64_t x, int bytenum)
64{
65 const char ch = x >> (bytenum * 8);
66 const uint64_t mask = ((ch >= 'a') && (ch <= 'z')) ? 0x20 : 0;
67 return mask << (bytenum * 8);
68}
69
76static inline bool eqi1(const char *a, const char b[1])
77{
78 uint8_t b8 = b[0];
79 return (*a | make_lowercase_mask(b8, 0)) == (unsigned char) b[0];
80}
81
88static inline bool eqi2(const char *a, const char b[2])
89{
90 uint16_t a16, b16;
91 memcpy(&a16, a, sizeof(a16));
92 memcpy(&b16, b, sizeof(b16));
93 const uint16_t lowercase_mask = make_lowercase_mask(b16, 0) |
94 make_lowercase_mask(b16, 1);
95 return (a16 | lowercase_mask) == b16;
96}
97
104static inline bool eqi4(const char *a, const char b[4])
105{
106 uint32_t a32, b32;
107 memcpy(&a32, a, sizeof(a32));
108 memcpy(&b32, b, sizeof(b32));
109 const uint32_t lowercase_mask = make_lowercase_mask(b32, 0) |
110 make_lowercase_mask(b32, 1) |
111 make_lowercase_mask(b32, 2) |
112 make_lowercase_mask(b32, 3);
113 return (a32 | lowercase_mask) == b32;
114}
115
122static inline bool eqi8(const char *a, const char b[8])
123{
124 uint64_t a64, b64;
125 memcpy(&a64, a, sizeof(a64));
126 memcpy(&b64, b, sizeof(b64));
127 const uint64_t lowercase_mask = make_lowercase_mask(b64, 0) |
128 make_lowercase_mask(b64, 1) |
129 make_lowercase_mask(b64, 2) |
130 make_lowercase_mask(b64, 3) |
131 make_lowercase_mask(b64, 4) |
132 make_lowercase_mask(b64, 5) |
133 make_lowercase_mask(b64, 6) |
134 make_lowercase_mask(b64, 7);
135 return (a64 | lowercase_mask) == b64;
136}
137
138/* various helpers for increased readability */
139
140/* there's no eqi3(); consider using eqi4() instead if you can */
141
143static inline bool eqi5(const char *a, const char b[5])
144{
145 return eqi4(a, b) && eqi1(a + 1, b + 1);
146}
147
149static inline bool eqi6(const char *a, const char b[6])
150{
151 return eqi4(a, b) && eqi2(a + 4, b + 4);
152}
153
154/* there's no eqi7(); consider using eqi8() instead if you can */
155
157static inline bool eqi9(const char *a, const char b[9])
158{
159 return eqi8(a, b) && eqi1(a + 8, b + 8);
160}
161
163static inline bool eqi10(const char *a, const char b[10])
164{
165 return eqi8(a, b) && eqi2(a + 8, b + 8);
166}
167
169static inline bool eqi11(const char *a, const char b[11])
170{
171 return eqi8(a, b) && eqi4(a + 7, b + 7);
172}
173
175static inline bool eqi12(const char *a, const char b[12])
176{
177 return eqi8(a, b) && eqi4(a + 8, b + 8);
178}
179
181static inline bool eqi13(const char *a, const char b[13])
182{
183 return eqi8(a, b) && eqi8(a + 5, b + 5);
184}
185
187static inline bool eqi14(const char *a, const char b[14])
188{
189 return eqi8(a, b) && eqi8(a + 6, b + 6);
190}
191
193static inline bool eqi15(const char *a, const char b[15])
194{
195 return eqi8(a, b) && eqi8(a + 7, b + 7);
196}
197
199static inline bool eqi16(const char *a, const char b[16])
200{
201 return eqi8(a, b) && eqi8(a + 8, b + 8);
202}
203
205static inline bool eqi17(const char *a, const char b[17])
206{
207 return eqi16(a, b) && eqi1(a + 16, b + 16);
208}
209
210#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:205
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:157
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:163
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:122
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:169
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:149
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:187
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:181
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:104
static uint64_t make_lowercase_mask(uint64_t x, int bytenum)
Create a mask to lowercase alphabetic characters.
Definition: eqi.h:63
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:143
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:175
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:199
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:193
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:76
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:88