// Copyright 2017 The Abseil Authors. // // Licensed 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 // // https://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. #include "absl/strings/str_split.h" #include <algorithm> #include <cstddef> #include <cstdlib> #include <cstring> #include "absl/base/config.h" #include "absl/base/internal/raw_logging.h" #include "absl/strings/string_view.h" namespace absl { ABSL_NAMESPACE_BEGIN namespace { // This GenericFind() template function encapsulates the finding algorithm // shared between the ByString and ByAnyChar delimiters. The FindPolicy // template parameter allows each delimiter to customize the actual find // function to use and the length of the found delimiter. For example, the // Literal delimiter will ultimately use absl::string_view::find(), and the // AnyOf delimiter will use absl::string_view::find_first_of(). template <typename FindPolicy> absl::string_view GenericFind(absl::string_view text, absl::string_view delimiter, size_t pos, FindPolicy find_policy) { … } // Finds using absl::string_view::find(), therefore the length of the found // delimiter is delimiter.length(). struct LiteralPolicy { … }; // Finds using absl::string_view::find_first_of(), therefore the length of the // found delimiter is 1. struct AnyOfPolicy { … }; } // namespace // // ByString // ByString::ByString(absl::string_view sp) : … { … } absl::string_view ByString::Find(absl::string_view text, size_t pos) const { … } absl::string_view ByAsciiWhitespace::Find(absl::string_view text, size_t pos) const { … } // // ByChar // absl::string_view ByChar::Find(absl::string_view text, size_t pos) const { … } // // ByAnyChar // ByAnyChar::ByAnyChar(absl::string_view sp) : … { … } absl::string_view ByAnyChar::Find(absl::string_view text, size_t pos) const { … } // // ByLength // ByLength::ByLength(ptrdiff_t length) : … { … } absl::string_view ByLength::Find(absl::string_view text, size_t pos) const { … } ABSL_NAMESPACE_END } // namespace absl