35 if (
'A' <= c && c <=
'Z') {
36 return 'a' + (c -
'A');
44 const int32_t str_len,
46 const int32_t pat_len,
49 int search_len = str_len - pat_len + 1;
50 for (i = 0; i < search_len; ++i) {
51 for (j = 0; j < pat_len && pattern[j] == str[j + i]; ++j) {
62 const int32_t str_len,
64 const int32_t pat_len,
67 int search_len = str_len - pat_len + 1;
68 for (i = 0; i < search_len; ++i) {
69 for (j = 0; j < pat_len && pattern[j] ==
lowercase(str[j + i]); ++j) {
78 #define STR_LIKE_SIMPLE_NULLABLE(base_func) \
79 extern "C" RUNTIME_EXPORT DEVICE int8_t base_func##_nullable(const char* lhs, \
80 const int32_t lhs_len, \
82 const int32_t rhs_len, \
84 const int8_t bool_null) { \
88 return base_func(lhs, lhs_len, rhs, rhs_len, escape_char) ? 1 : 0; \
94 #undef STR_LIKE_SIMPLE_NULLABLE
99 const int32_t str_len,
101 const int32_t pat_len,
102 const char escape_char,
103 const bool is_ilike) {
106 const char* p = pattern;
109 while (slen > 0 && plen > 0) {
110 if (*p == escape_char) {
117 if ((!is_ilike && *s != *p) || (is_ilike &&
lowercase(*s) != *p)) {
120 }
else if (*p ==
'%') {
128 }
else if (*p ==
'_') {
143 if (*p == escape_char) {
154 if (firstpat ==
'[' && *p != escape_char) {
155 const char* pp = p + 1;
156 int pplen = plen - 1;
157 while (pplen > 0 && *pp !=
']') {
158 if ((!is_ilike && *s == *pp) || (is_ilike &&
lowercase(*s) == *pp)) {
168 }
else if ((!is_ilike && *s == firstpat) ||
169 (is_ilike &&
lowercase(*s) == firstpat)) {
182 }
else if (*p ==
'_') {
188 }
else if (*p ==
'[') {
189 const char* pp = p + 1;
190 int pplen = plen - 1;
192 while (pplen > 0 && *pp !=
']') {
193 if ((!is_ilike && *s == *pp) || (is_ilike &&
lowercase(*s) == *pp)) {
205 for (x = pp + 1; *x !=
']' && pplen > 0; x++, pplen--) {
217 }
else if ((!is_ilike && *s != *p) || (is_ilike &&
lowercase(*s) != *p)) {
228 while (plen > 0 && *p ==
'%') {
251 const int32_t str_len,
253 const int32_t pat_len,
254 const char escape_char) {
262 const int32_t str_len,
264 const int32_t pat_len,
265 const char escape_char) {
273 const int32_t s1_len,
275 const int32_t s2_len) {
276 const char* s1_ = s1;
277 const char* s2_ = s2;
279 while (s1_ < s1 + s1_len && s2_ < s2 + s2_len && *s1_ == *s2_) {
284 unsigned char c1 = (s1_ < s1 + s1_len) ? (*(
unsigned char*)s1_) : 0;
285 unsigned char c2 = (s2_ < s2 + s2_len) ? (*(
unsigned char*)s2_) : 0;
290 #define STR_LIKE_NULLABLE(base_func) \
291 extern "C" RUNTIME_EXPORT DEVICE int8_t base_func##_nullable(const char* lhs, \
292 const int32_t lhs_len, \
294 const int32_t rhs_len, \
295 const char escape_char, \
296 const int8_t bool_null) { \
297 if (!lhs || !rhs) { \
300 return base_func(lhs, lhs_len, rhs, rhs_len, escape_char) ? 1 : 0; \
306 #undef STR_LIKE_NULLABLE
309 const int32_t lhs_len,
311 const int32_t rhs_len) {
316 const int32_t lhs_len,
318 const int32_t rhs_len) {
323 const int32_t lhs_len,
325 const int32_t rhs_len) {
330 const int32_t lhs_len,
332 const int32_t rhs_len) {
337 const int32_t lhs_len,
339 const int32_t rhs_len) {
344 const int32_t lhs_len,
346 const int32_t rhs_len) {
350 #define STR_CMP_NULLABLE(base_func) \
351 extern "C" RUNTIME_EXPORT DEVICE int8_t base_func##_nullable(const char* lhs, \
352 const int32_t lhs_len, \
354 const int32_t rhs_len, \
355 const int8_t bool_null) { \
356 if (!lhs || !rhs) { \
359 return base_func(lhs, lhs_len, rhs, rhs_len) ? 1 : 0; \
369 #undef STR_CMP_NULLABLE
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
RUNTIME_EXPORT DEVICE bool string_eq(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_gt(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_ilike_simple(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, char escape_char)
RUNTIME_EXPORT DEVICE bool string_le(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_ge(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_lt(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
#define STR_LIKE_NULLABLE(base_func)
#define STR_LIKE_SIMPLE_NULLABLE(base_func)
static DEVICE LikeStatus string_like_match(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char, const bool is_ilike)
RUNTIME_EXPORT DEVICE bool string_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
static DEVICE int lowercase(char c)
Functions to support the LIKE and ILIKE operator in SQL. Only single-byte character set is supported ...
RUNTIME_EXPORT DEVICE bool string_like_simple(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, char escape_char)
#define STR_CMP_NULLABLE(base_func)
RUNTIME_EXPORT DEVICE bool string_ne(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_ilike(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)