Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: tools/gn/token.cc

Issue 21114002: Add initial prototype for the GN meta-buildsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add owners and readme Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/token.h ('k') | tools/gn/tokenizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "tools/gn/token.h"
6
7 #include "base/logging.h"
8
9 namespace {
10
11 std::string UnescapeString(const base::StringPiece& input) {
12 std::string result;
13 result.reserve(input.size());
14
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.
20 }
21 result.push_back(input[i]);
22 }
23 return result;
24 }
25
26 } // namespace
27
28 Token::Token() : type_(INVALID), value_() {
29 }
30
31 Token::Token(const Location& location,
32 Type t,
33 const base::StringPiece& v)
34 : type_(t),
35 value_(v),
36 location_(location) {
37 }
38
39 bool Token::IsIdentifierEqualTo(const char* v) const {
40 return type_ == IDENTIFIER && value_ == v;
41 }
42
43 bool Token::IsOperatorEqualTo(const char* v) const {
44 return type_ == OPERATOR && value_ == v;
45 }
46
47 bool Token::IsScoperEqualTo(const char* v) const {
48 return type_ == SCOPER && value_ == v;
49 }
50
51 bool Token::IsStringEqualTo(const char* v) const {
52 return type_ == STRING && value_ == v;
53 }
54
55 std::string Token::StringValue() const {
56 DCHECK(type() == STRING);
57
58 // Trim off the string terminators at the end.
59 return UnescapeString(value_.substr(1, value_.size() - 2));
60 }
OLDNEW
« no previous file with comments | « tools/gn/token.h ('k') | tools/gn/tokenizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698