| Flutter Impeller |

strings.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/base/strings.h"
6
7 namespace impeller {
8
9 bool HasPrefix(const std::string& string, const std::string& prefix) {
10 return string.find(prefix) == 0u;
11 }
12
13 bool HasSuffix(const std::string& string, const std::string& suffix) {
14 auto position = string.rfind(suffix);
15 if (position == std::string::npos) {
16 return false;
17 }
18 return position == string.size() - suffix.size();
19 }
20
21 std::string StripPrefix(const std::string& string,
22 const std::string& to_strip) {
23 if (!HasPrefix(string, to_strip)) {
24 return string;
25 }
26 return string.substr(to_strip.length());
27 }
28
29 } // namespace impeller
impeller
Definition: allocation.cc:12
impeller::HasPrefix
bool HasPrefix(const std::string &string, const std::string &prefix)
Definition: strings.cc:9
impeller::HasSuffix
bool HasSuffix(const std::string &string, const std::string &suffix)
Definition: strings.cc:13
impeller::StripPrefix
std::string StripPrefix(const std::string &string, const std::string &to_strip)
Definition: strings.cc:21
strings.h