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

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

Issue 588893006: gn: attach comments to parse tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x64 Created 6 years, 2 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
« no previous file with comments | « tools/gn/scope_unittest.cc ('k') | tools/gn/token.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/string_utils.h" 5 #include "tools/gn/string_utils.h"
6 6
7 #include "tools/gn/err.h" 7 #include "tools/gn/err.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 #include "tools/gn/token.h" 9 #include "tools/gn/token.h"
10 #include "tools/gn/tokenizer.h" 10 #include "tools/gn/tokenizer.h"
11 #include "tools/gn/value.h" 11 #include "tools/gn/value.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Constructs an Err indicating a range inside a string. We assume that the 15 // Constructs an Err indicating a range inside a string. We assume that the
16 // token has quotes around it that are not counted by the offset. 16 // token has quotes around it that are not counted by the offset.
17 Err ErrInsideStringToken(const Token& token, size_t offset, size_t size, 17 Err ErrInsideStringToken(const Token& token, size_t offset, size_t size,
18 const std::string& msg, 18 const std::string& msg,
19 const std::string& help = std::string()) { 19 const std::string& help = std::string()) {
20 // The "+1" is skipping over the " at the beginning of the token. 20 // The "+1" is skipping over the " at the beginning of the token.
21 int int_offset = static_cast<int>(offset); 21 int int_offset = static_cast<int>(offset);
22 Location begin_loc(token.location().file(), 22 Location begin_loc(token.location().file(),
23 token.location().line_number(), 23 token.location().line_number(),
24 token.location().char_offset() + int_offset + 1); 24 token.location().char_offset() + int_offset + 1,
25 Location end_loc(token.location().file(), 25 token.location().byte() + int_offset + 1);
26 token.location().line_number(), 26 Location end_loc(
27 token.location().char_offset() + int_offset + 1 + 27 token.location().file(),
28 static_cast<int>(size)); 28 token.location().line_number(),
29 token.location().char_offset() + int_offset + 1 + static_cast<int>(size),
30 token.location().byte() + int_offset + 1 + static_cast<int>(size));
29 return Err(LocationRange(begin_loc, end_loc), msg, help); 31 return Err(LocationRange(begin_loc, end_loc), msg, help);
30 } 32 }
31 33
32 // Given the character input[i] indicating the $ in a string, locates the 34 // Given the character input[i] indicating the $ in a string, locates the
33 // identifier and places its range in |*identifier|, and updates |*i| to 35 // identifier and places its range in |*identifier|, and updates |*i| to
34 // point to the last character consumed. 36 // point to the last character consumed.
35 // 37 //
36 // On error returns false and sets the error. 38 // On error returns false and sets the error.
37 bool LocateInlineIdenfitier(const Token& token, 39 bool LocateInlineIdenfitier(const Token& token,
38 const char* input, size_t size, 40 const char* input, size_t size,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 str.compare(0, prefix.size(), prefix) == 0); 170 str.compare(0, prefix.size(), prefix) == 0);
169 return str.substr(prefix.size()); 171 return str.substr(prefix.size());
170 } 172 }
171 173
172 void TrimTrailingSlash(std::string* str) { 174 void TrimTrailingSlash(std::string* str) {
173 if (!str->empty()) { 175 if (!str->empty()) {
174 DCHECK((*str)[str->size() - 1] == '/'); 176 DCHECK((*str)[str->size() - 1] == '/');
175 str->resize(str->size() - 1); 177 str->resize(str->size() - 1);
176 } 178 }
177 } 179 }
OLDNEW
« no previous file with comments | « tools/gn/scope_unittest.cc ('k') | tools/gn/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698