cosmopolitan/libc/str/has_char.h
Justine Tunney 7c83f4abc8
Make improvements
- wcsstr() is now linearly complex
- strstr16() is now linearly complex
- strstr() is now vectorized on aarch64 (10x)
- strstr() now uses KMP on pathological cases
- memmem() is now vectorized on aarch64 (10x)
- memmem() now uses KMP on pathological cases
- Disable shared_ptr::owner_before until fixed
- Make iswlower(), iswupper() consistent with glibc
- Remove figure space from iswspace() implementation
- Include line and paragraph separator in iswcntrl()
- Use Musl wcwidth(), iswalpha(), iswpunct(), towlower(), towupper()
2024-09-01 01:27:47 -07:00

24 lines
543 B
C++

// -*- c++ -*-
#ifndef COSMOPOLITAN_LIBC_STR_HAS_CHAR_H_
#define COSMOPOLITAN_LIBC_STR_HAS_CHAR_H_
#ifdef __cplusplus
template <typename T>
static bool has_char(const T (*ranges)[2], size_t n, T c) {
unsigned l = 0;
unsigned r = n;
while (l < r) {
unsigned m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
if (c < ranges[m][0]) {
r = m;
} else if (c > ranges[m][1]) {
l = m + 1;
} else {
return true;
}
}
return false;
}
#endif /* __cplusplus */
#endif /* COSMOPOLITAN_LIBC_STR_HAS_CHAR_H_ */