00001 // Copyright 2017 The Abseil Authors. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // https://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 #include "absl/strings/match.h" 00016 00017 #include "absl/strings/internal/memutil.h" 00018 00019 namespace absl { 00020 00021 bool EqualsIgnoreCase(absl::string_view piece1, absl::string_view piece2) { 00022 return (piece1.size() == piece2.size() && 00023 0 == absl::strings_internal::memcasecmp(piece1.data(), piece2.data(), 00024 piece1.size())); 00025 // memcasecmp uses absl::ascii_tolower(). 00026 } 00027 00028 bool StartsWithIgnoreCase(absl::string_view text, absl::string_view prefix) { 00029 return (text.size() >= prefix.size()) && 00030 EqualsIgnoreCase(text.substr(0, prefix.size()), prefix); 00031 } 00032 00033 bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix) { 00034 return (text.size() >= suffix.size()) && 00035 EqualsIgnoreCase(text.substr(text.size() - suffix.size()), suffix); 00036 } 00037 00038 } // namespace absl