// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include namespace doris { inline std::string to_lower(const std::string& input) { std::string output; output.resize(input.size()); std::transform(input.begin(), input.end(), output.begin(), [](unsigned char c) { return std::tolower(c); }); return output; } inline std::string to_upper(const std::string& input) { std::string output; output.resize(input.size()); std::transform(input.begin(), input.end(), output.begin(), [](unsigned char c) { return std::toupper(c); }); return output; } inline bool iequal(const std::string& lhs, const std::string& rhs) { if (lhs.size() != rhs.size()) { return false; } return to_lower(lhs) == to_lower(rhs); } inline bool starts_with(const std::string& value, const std::string& beginning) { return value.find(beginning) == 0; } inline bool ends_with(std::string const& value, std::string const& ending) { if (ending.size() > value.size()) { return false; } return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); } inline std::vector split(const std::string& s, const std::string& delim) { std::vector out; size_t pos {}; for (size_t find = 0; (find = s.find(delim, pos)) != std::string::npos; pos = find + delim.size()) { out.emplace_back(s.data() + pos, s.data() + find); } out.emplace_back(s.data() + pos, s.data() + s.size()); return out; } template std::string join(const std::vector& elems, const std::string& delim) { std::stringstream ss; for (size_t i = 0; i < elems.size(); ++i) { if (i != 0) { ss << delim.c_str(); } ss << elems[i]; } return ss.str(); } struct StringCaseHasher { public: std::size_t operator()(const std::string& value) const { std::string lower_value = to_lower(value); return std::hash()(lower_value); } }; struct StringCaseEqual { public: bool operator()(const std::string& lhs, const std::string& rhs) const { if (lhs.size() != rhs.size()) { return false; } return strncasecmp(lhs.c_str(), rhs.c_str(), lhs.size()) == 0; } }; struct StringCaseLess { public: bool operator()(const std::string& lhs, const std::string& rhs) const { size_t common_size = std::min(lhs.size(), rhs.size()); auto cmp = strncasecmp(lhs.c_str(), rhs.c_str(), common_size); if (cmp == 0) { return lhs.size() < rhs.size(); } return cmp < 0; } }; size_t hash_of_path(const std::string& identifier, const std::string& path); using StringCaseSet = std::set; using StringCaseUnorderedSet = std::unordered_set; template using StringCaseMap = std::map; template using StringCaseUnorderedMap = std::unordered_map; template auto get_json_token(T& path_string) { return boost::tokenizer>( path_string, boost::escaped_list_separator("\\", ".", "\"")); } #ifdef USE_LIBCPP template <> auto get_json_token(std::string_view& path_string) = delete; #endif } // namespace doris