OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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

DEVICE bool string_like (const char *str, int str_len, const char *pattern, int pat_len, char escape_char)
 
DEVICE bool string_ilike (const char *str, int str_len, const char *pattern, int pat_len, char escape_char)
 
DEVICE bool string_like_simple (const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
 
DEVICE bool string_ilike_simple (const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
 
DEVICE bool string_lt (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
DEVICE bool string_le (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
DEVICE bool string_eq (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
DEVICE bool string_ne (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
DEVICE bool string_ge (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
DEVICE bool string_gt (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
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.

Author
Wei Hong wei@m.nosp@m.apd..nosp@m.com Copyright (c) 2014 MapD Technologies, Inc. All rights reserved.

Definition in file StringLike.h.

Function Documentation

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

Definition at line 332 of file StringLike.cpp.

References StringCompare().

Referenced by StringDictionary::getCompare().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 325 of file StringLike.cpp.

References StringCompare().

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

+ Here is the call graph for this function:

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

Definition at line 318 of file StringLike.cpp.

References StringCompare().

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

+ Here is the call graph for this function:

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

Definition at line 59 of file StringLike.cpp.

References lowercase().

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 311 of file StringLike.cpp.

References StringCompare().

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

+ Here is the call graph for this function:

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

Definition at line 43 of file StringLike.cpp.

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

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

+ Here is the caller graph for this function:

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

Definition at line 304 of file StringLike.cpp.

References StringCompare().

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 339 of file StringLike.cpp.

References StringCompare().

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

+ Here is the call graph for this function:

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

Definition at line 268 of file StringLike.cpp.

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

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

+ Here is the caller graph for this function: