OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Regexp.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #include "Regexp.h"
26 
27 #ifndef __CUDACC__
28 #include <boost/regex.hpp>
29 #endif
30 
31 /*
32  * @brief regexp_like performs the SQL REGEXP operation
33  * @param str string argument to be matched against pattern.
34  * @param str_len length of str
35  * @param pattern regex pattern string for SQL REGEXP
36  * @param pat_len length of pattern
37  * @param escape_char the escape character. '\\' is expected by default.
38  * @return true if str matches pattern, false otherwise.
39  */
40 extern "C" DEVICE bool regexp_like(const char* str,
41  const int32_t str_len,
42  const char* pattern,
43  const int32_t pat_len,
44  const char escape_char) {
45 #ifndef __CUDACC__
46  bool result;
47  try {
48  boost::regex re(pattern, pat_len, boost::regex::extended);
49  boost::cmatch what;
50  result = boost::regex_match(str, str + str_len, what, re);
51  } catch (std::runtime_error& error) {
52  // LOG(ERROR) << "Regexp match error: " << error.what();
53  result = false;
54  }
55  return result;
56 #else
57  return false;
58 #endif
59 }
60 
61 extern "C" DEVICE int8_t regexp_like_nullable(const char* str,
62  const int32_t str_len,
63  const char* pattern,
64  const int32_t pat_len,
65  const char escape_char,
66  const int8_t bool_null) {
67  if (!str || !pattern) {
68  return bool_null;
69  }
70 
71  return regexp_like(str, str_len, pattern, pat_len, escape_char);
72 }
#define DEVICE
DEVICE bool regexp_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: Regexp.cpp:40
DEVICE int8_t regexp_like_nullable(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char, const int8_t bool_null)
Definition: Regexp.cpp:61