1#include "duckdb/function/scalar/string_functions.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/vector_operations/vector_operations.hpp"
5#include "duckdb/common/vector_operations/unary_executor.hpp"
6#include "duckdb/planner/expression/bound_function_expression.hpp"
7#include "duckdb/common/vector_operations/unary_executor.hpp"
8
9#include <ctype.h>
10#include <cstring>
11
12using namespace std;
13
14namespace duckdb {
15
16static bool contains_strstr(const string_t &str, const string_t &pattern);
17
18struct ContainsOperator {
19 template <class TA, class TB, class TR> static inline TR Operation(TA left, TB right) {
20 return contains_strstr(left, right);
21 }
22};
23
24static bool contains_strstr(const string_t &str, const string_t &pattern) {
25 auto str_data = str.GetData();
26 auto patt_data = pattern.GetData();
27 return (strstr(str_data, patt_data) != nullptr);
28}
29
30ScalarFunction ContainsFun::GetFunction() {
31 return ScalarFunction("contains", // name of the function
32 {SQLType::VARCHAR, SQLType::VARCHAR}, // argument list
33 SQLType::BOOLEAN, // return type
34 ScalarFunction::BinaryFunction<string_t, string_t, bool, ContainsOperator, true>);
35}
36
37void ContainsFun::RegisterFunction(BuiltinFunctions &set) {
38 set.AddFunction(GetFunction());
39}
40
41} // namespace duckdb
42