Correct blacklist entry message
[chromium-blink-merge.git] / tools / gn / token.cc
blobba595267470a80d3dad85215cabad6c32c401940
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 #include "tools/gn/token.h"
7 #include "base/logging.h"
9 namespace {
11 std::string UnescapeString(const base::StringPiece& input) {
12 std::string result;
13 result.reserve(input.size());
15 for (size_t i = 0; i < input.size(); i++) {
16 if (input[i] == '\\') {
17 DCHECK(i < input.size() - 1); // Last char shouldn't be a backslash or
18 // it would have escaped the terminator.
19 i++; // Skip backslash, next char is a literal.
21 result.push_back(input[i]);
23 return result;
26 } // namespace
28 Token::Token() : type_(INVALID), value_() {
31 Token::Token(const Location& location,
32 Type t,
33 const base::StringPiece& v)
34 : type_(t),
35 value_(v),
36 location_(location) {
39 bool Token::IsIdentifierEqualTo(const char* v) const {
40 return type_ == IDENTIFIER && value_ == v;
43 bool Token::IsStringEqualTo(const char* v) const {
44 return type_ == STRING && value_ == v;
47 std::string Token::StringValue() const {
48 DCHECK(type() == STRING);
50 // Trim off the string terminators at the end.
51 return UnescapeString(value_.substr(1, value_.size() - 2));