OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringLike.h File Reference

Functions to support the LIKE and ILIKE operator in SQL. Only single-byte character set is supported for now. More...

#include "../Shared/funcannotations.h"
#include <cstdint>
+ Include dependency graph for StringLike.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

RUNTIME_EXPORT DEVICE bool string_like (const char *str, int str_len, const char *pattern, int pat_len, char escape_char)
 
RUNTIME_EXPORT DEVICE bool string_ilike (const char *str, int str_len, const char *pattern, int pat_len, char escape_char)
 
RUNTIME_EXPORT DEVICE bool string_like_simple (const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
 
RUNTIME_EXPORT DEVICE bool string_ilike_simple (const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
 
RUNTIME_EXPORT DEVICE bool string_lt (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
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_eq (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
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_ge (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 int32_t StringCompare (const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
 

Detailed Description

Functions to support the LIKE and ILIKE operator in SQL. Only single-byte character set is supported for now.

Definition in file StringLike.h.

Function Documentation

RUNTIME_EXPORT DEVICE bool string_eq ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 330 of file StringLike.cpp.

References StringCompare().

Referenced by StringDictionary::getCompare().

333  {
334  return StringCompare(lhs, lhs_len, rhs, rhs_len) == 0;
335 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_ge ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 323 of file StringLike.cpp.

References StringCompare().

326  {
327  return StringCompare(lhs, lhs_len, rhs, rhs_len) >= 0;
328 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:266

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE bool string_gt ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 316 of file StringLike.cpp.

References StringCompare().

319  {
320  return StringCompare(lhs, lhs_len, rhs, rhs_len) > 0;
321 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:266

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE bool string_ilike ( const char *  str,
int  str_len,
const char *  pattern,
int  pat_len,
char  escape_char 
)
RUNTIME_EXPORT DEVICE bool string_ilike_simple ( const char *  str,
const int32_t  str_len,
const char *  pattern,
const int32_t  pat_len 
)

Definition at line 57 of file StringLike.cpp.

References lowercase().

Referenced by anonymous_namespace{StringDictionaryProxy.cpp}::is_like(), and anonymous_namespace{StringDictionary.cpp}::is_like().

60  {
61  int i, j;
62  int search_len = str_len - pat_len + 1;
63  for (i = 0; i < search_len; ++i) {
64  for (j = 0; j < pat_len && pattern[j] == lowercase(str[j + i]); ++j) {
65  }
66  if (j >= pat_len) {
67  return true;
68  }
69  }
70  return false;
71 }
static DEVICE int lowercase(char c)
Definition: StringLike.cpp:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_le ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 309 of file StringLike.cpp.

References StringCompare().

312  {
313  return StringCompare(lhs, lhs_len, rhs, rhs_len) <= 0;
314 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:266

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE bool string_like ( const char *  str,
int  str_len,
const char *  pattern,
int  pat_len,
char  escape_char 
)
RUNTIME_EXPORT DEVICE bool string_like_simple ( const char *  str,
const int32_t  str_len,
const char *  pattern,
const int32_t  pat_len 
)

Definition at line 41 of file StringLike.cpp.

Referenced by anonymous_namespace{StringDictionaryProxy.cpp}::is_like(), and anonymous_namespace{StringDictionary.cpp}::is_like().

44  {
45  int i, j;
46  int search_len = str_len - pat_len + 1;
47  for (i = 0; i < search_len; ++i) {
48  for (j = 0; j < pat_len && pattern[j] == str[j + i]; ++j) {
49  }
50  if (j >= pat_len) {
51  return true;
52  }
53  }
54  return false;
55 }

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_lt ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 302 of file StringLike.cpp.

References StringCompare().

Referenced by StringDictionary::getCompare(), StringDictionary::mergeSortedCache(), and StringDictionary::sortCache().

305  {
306  return StringCompare(lhs, lhs_len, rhs, rhs_len) < 0;
307 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_ne ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 337 of file StringLike.cpp.

References StringCompare().

340  {
341  return StringCompare(lhs, lhs_len, rhs, rhs_len) != 0;
342 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:266

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE int32_t StringCompare ( const char *  s1,
const int32_t  s1_len,
const char *  s2,
const int32_t  s2_len 
)

Definition at line 266 of file StringLike.cpp.

Referenced by string_eq(), string_ge(), string_gt(), string_le(), string_lt(), and string_ne().

269  {
270  const char* s1_ = s1;
271  const char* s2_ = s2;
272 
273  while (s1_ < s1 + s1_len && s2_ < s2 + s2_len && *s1_ == *s2_) {
274  s1_++;
275  s2_++;
276  }
277 
278  unsigned char c1 = (s1_ < s1 + s1_len) ? (*(unsigned char*)s1_) : 0;
279  unsigned char c2 = (s2_ < s2 + s2_len) ? (*(unsigned char*)s2_) : 0;
280 
281  return c1 - c2;
282 }

+ Here is the caller graph for this function: