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"
11 std::string
UnescapeString(const base::StringPiece
& input
) {
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
]);
28 Token::Token() : type_(INVALID
), value_() {
31 Token::Token(const Location
& location
,
33 const base::StringPiece
& v
)
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));