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 <stddef.h> | 7 #include <stddef.h> |
8 #include <cctype> | 8 #include <cctype> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // The error will point into our temporary buffer, rewrite it to refer | 74 // The error will point into our temporary buffer, rewrite it to refer |
75 // to the original token. This will make the location information less | 75 // to the original token. This will make the location information less |
76 // precise, but generally there won't be complicated things in string | 76 // precise, but generally there won't be complicated things in string |
77 // interpolations. | 77 // interpolations. |
78 *err = ErrInsideStringToken(token, begin_offset, end_offset - begin_offset, | 78 *err = ErrInsideStringToken(token, begin_offset, end_offset - begin_offset, |
79 err->message(), err->help_text()); | 79 err->message(), err->help_text()); |
80 return false; | 80 return false; |
81 } | 81 } |
82 | 82 |
83 // Parse. | 83 // Parse. |
84 scoped_ptr<ParseNode> node = Parser::ParseExpression(tokens, err); | 84 std::unique_ptr<ParseNode> node = Parser::ParseExpression(tokens, err); |
85 if (err->has_error()) { | 85 if (err->has_error()) { |
86 // Rewrite error as above. | 86 // Rewrite error as above. |
87 *err = ErrInsideStringToken(token, begin_offset, end_offset - begin_offset, | 87 *err = ErrInsideStringToken(token, begin_offset, end_offset - begin_offset, |
88 err->message(), err->help_text()); | 88 err->message(), err->help_text()); |
89 return false; | 89 return false; |
90 } | 90 } |
91 if (!(node->AsIdentifier() || node->AsAccessor())) { | 91 if (!(node->AsIdentifier() || node->AsAccessor())) { |
92 *err = ErrInsideStringToken(token, begin_offset, end_offset - begin_offset, | 92 *err = ErrInsideStringToken(token, begin_offset, end_offset - begin_offset, |
93 "Invalid string interpolation.", | 93 "Invalid string interpolation.", |
94 "The thing inside the ${} must be an identifier ${foo},\n" | 94 "The thing inside the ${} must be an identifier ${foo},\n" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 base::StringPiece result; | 336 base::StringPiece result; |
337 for (base::StringPiece word : words) { | 337 for (base::StringPiece word : words) { |
338 size_t distance = EditDistance(word, text, kMaxValidEditDistance); | 338 size_t distance = EditDistance(word, text, kMaxValidEditDistance); |
339 if (distance < min_distance) { | 339 if (distance < min_distance) { |
340 min_distance = distance; | 340 min_distance = distance; |
341 result = word; | 341 result = word; |
342 } | 342 } |
343 } | 343 } |
344 return result; | 344 return result; |
345 } | 345 } |
OLD | NEW |