2 * Copyright 2021 Google LLC.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkStringView_DEFINED
9 #define SkStringView_DEFINED
12 #include <string_view>
17 inline constexpr bool starts_with(std::string_view str, std::string_view prefix) {
18 if (prefix.length() > str.length()) {
21 return prefix.length() == 0 || !memcmp(str.data(), prefix.data(), prefix.length());
24 inline constexpr bool starts_with(std::string_view str, std::string_view::value_type c) {
25 return !str.empty() && str.front() == c;
28 inline constexpr bool ends_with(std::string_view str, std::string_view suffix) {
29 if (suffix.length() > str.length()) {
32 return suffix.length() == 0 || !memcmp(str.data() + str.length() - suffix.length(),
33 suffix.data(), suffix.length());
36 inline constexpr bool ends_with(std::string_view str, std::string_view::value_type c) {
37 return !str.empty() && str.back() == c;
41 inline constexpr bool contains(std::string_view str, std::string_view needle) {
42 return str.find(needle) != std::string_view::npos;