OmniSciDB  04ee39c94c
import_helpers.h
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 
17 #ifndef IMPORT_HELPERS_H_
18 #define IMPORT_HELPERS_H_
19 
21 #include <boost/algorithm/string.hpp>
22 #include <boost/algorithm/string/replace.hpp>
23 #include <boost/regex.hpp>
24 
25 namespace ImportHelpers {
26 
27 inline bool is_reserved_name(const std::string& name) {
28  return reserved_keywords.find(boost::to_upper_copy<std::string>(name)) !=
29  reserved_keywords.end();
30 }
31 
32 inline std::string sanitize_name(const std::string& name) {
33  boost::regex invalid_chars{R"([^0-9a-z_])",
34  boost::regex::extended | boost::regex::icase};
35  std::string sanitized_name = boost::regex_replace(name, invalid_chars, "");
36  if (is_reserved_name(sanitized_name)) {
37  sanitized_name += "_";
38  }
39  return sanitized_name;
40 }
41 
42 } // namespace ImportHelpers
43 
44 #endif // IMPORT_HELPERS_H_
static std::set< std::string > reserved_keywords
bool is_reserved_name(const std::string &name)
std::string sanitize_name(const std::string &name)