OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
import_helpers.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
17 #ifndef IMPORT_HELPERS_H_
18 #define IMPORT_HELPERS_H_
19 
21 
23 #include <boost/algorithm/string.hpp>
24 #include <boost/algorithm/string/replace.hpp>
25 
26 namespace ImportHelpers {
27 
28 inline bool is_reserved_name(const std::string& name) {
29  return reserved_keywords.find(boost::to_upper_copy<std::string>(name)) !=
30  reserved_keywords.end();
31 }
32 
33 inline std::string sanitize_name(const std::string& name) {
34  boost::regex invalid_chars{R"([^0-9a-z_])",
35  boost::regex::extended | boost::regex::icase};
36  std::string sanitized_name = boost::regex_replace(name, invalid_chars, "");
37  boost::regex starts_with_digit{R"(^[0-9].*)"};
38  if (boost::regex_match(sanitized_name, starts_with_digit)) {
39  sanitized_name = "_" + sanitized_name;
40  }
41  if (is_reserved_name(sanitized_name)) {
42  sanitized_name += "_";
43  }
44  return sanitized_name;
45 }
46 
47 template <typename DatumStringType>
48 inline bool is_null_datum(const DatumStringType& datum,
49  const std::string& null_indicator) {
50  return datum == null_indicator || datum == "NULL" || datum == "\\N";
51 }
52 
53 } // namespace ImportHelpers
54 
55 #endif // IMPORT_HELPERS_H_
static std::set< std::string > reserved_keywords
bool is_null_datum(const DatumStringType &datum, const std::string &null_indicator)
bool is_reserved_name(const std::string &name)
std::string sanitize_name(const std::string &name)
string name
Definition: setup.in.py:72