| OLD | NEW |
| 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 Location begin_loc(token.location().file(), | 22 Location begin_loc(token.location().file(), |
| 22 token.location().line_number(), | 23 token.location().line_number(), |
| 23 token.location().char_offset() + offset + 1); | 24 token.location().char_offset() + int_offset + 1); |
| 24 Location end_loc(token.location().file(), | 25 Location end_loc(token.location().file(), |
| 25 token.location().line_number(), | 26 token.location().line_number(), |
| 26 token.location().char_offset() + offset + 1 + size); | 27 token.location().char_offset() + int_offset + 1 + |
| 28 static_cast<int>(size)); |
| 27 return Err(LocationRange(begin_loc, end_loc), msg, help); | 29 return Err(LocationRange(begin_loc, end_loc), msg, help); |
| 28 } | 30 } |
| 29 | 31 |
| 30 // Given the character input[i] indicating the $ in a string, locates the | 32 // Given the character input[i] indicating the $ in a string, locates the |
| 31 // identifier and places its range in |*identifier|, and updates |*i| to | 33 // identifier and places its range in |*identifier|, and updates |*i| to |
| 32 // point to the last character consumed. | 34 // point to the last character consumed. |
| 33 // | 35 // |
| 34 // On error returns false and sets the error. | 36 // On error returns false and sets the error. |
| 35 bool LocateInlineIdenfitier(const Token& token, | 37 bool LocateInlineIdenfitier(const Token& token, |
| 36 const char* input, size_t size, | 38 const char* input, size_t size, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 161 } |
| 160 } | 162 } |
| 161 return true; | 163 return true; |
| 162 } | 164 } |
| 163 | 165 |
| 164 std::string RemovePrefix(const std::string& str, const std::string& prefix) { | 166 std::string RemovePrefix(const std::string& str, const std::string& prefix) { |
| 165 CHECK(str.size() >= prefix.size() && | 167 CHECK(str.size() >= prefix.size() && |
| 166 str.compare(0, prefix.size(), prefix) == 0); | 168 str.compare(0, prefix.size(), prefix) == 0); |
| 167 return str.substr(prefix.size()); | 169 return str.substr(prefix.size()); |
| 168 } | 170 } |
| OLD | NEW |