Add Media Router Action stub implementation.
[chromium-blink-merge.git] / tools / gn / string_utils.h
bloba405cc5e0199c0a2f2c578da0d763a657760c868
1 // Copyright (c) 2013 The Chromium 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.
5 #ifndef TOOLS_GN_STRING_UTILS_H_
6 #define TOOLS_GN_STRING_UTILS_H_
8 #include "base/strings/string_piece.h"
10 class Err;
11 class Scope;
12 class Token;
13 class Value;
15 inline std::string operator+(const std::string& a, const base::StringPiece& b) {
16 std::string ret;
17 ret.reserve(a.size() + b.size());
18 ret.assign(a);
19 ret.append(b.data(), b.size());
20 return ret;
23 inline std::string operator+(const base::StringPiece& a, const std::string& b) {
24 std::string ret;
25 ret.reserve(a.size() + b.size());
26 ret.assign(a.data(), a.size());
27 ret.append(b);
28 return ret;
31 // Unescapes and expands variables in the given literal, writing the result
32 // to the given value. On error, sets |err| and returns false.
33 bool ExpandStringLiteral(Scope* scope,
34 const Token& literal,
35 Value* result,
36 Err* err);
38 // Removes the given prefix from the string. Asserts if the string does
39 // not have the given prefix.
41 // Note: could potentially return a StringPiece into the str.
42 std::string RemovePrefix(const std::string& str, const std::string& prefix);
44 // Appends the given string piece to the given string. This avoids an
45 // intermediate copy.
46 inline void AppendStringPiece(std::string* dest,
47 const base::StringPiece& piece) {
48 dest->append(piece.data(), piece.size());
51 // Removes the trailing slash from the given string. This asserts that either
52 // the string is empty or it ends with a slash (normally used to process
53 // directories).
54 void TrimTrailingSlash(std::string* str);
56 #endif // TOOLS_GN_STRING_UTILS_H_