| 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/input_conversion.h" | 5 #include "tools/gn/input_conversion.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "tools/gn/build_settings.h" | 9 #include "tools/gn/build_settings.h" |
| 10 #include "tools/gn/err.h" | 10 #include "tools/gn/err.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 std::vector<std::string> as_lines; | 98 std::vector<std::string> as_lines; |
| 99 base::SplitString(input, '\n', &as_lines); | 99 base::SplitString(input, '\n', &as_lines); |
| 100 | 100 |
| 101 // Trim one empty line from the end since the last line might end in a | 101 // Trim one empty line from the end since the last line might end in a |
| 102 // newline. If the user wants more trimming, they'll specify "trim" in the | 102 // newline. If the user wants more trimming, they'll specify "trim" in the |
| 103 // input conversion options. | 103 // input conversion options. |
| 104 if (!as_lines.empty() && as_lines[as_lines.size() - 1].empty()) | 104 if (!as_lines.empty() && as_lines[as_lines.size() - 1].empty()) |
| 105 as_lines.resize(as_lines.size() - 1); | 105 as_lines.resize(as_lines.size() - 1); |
| 106 | 106 |
| 107 ret.list_value().reserve(as_lines.size()); | 107 ret.list_value().reserve(as_lines.size()); |
| 108 for (size_t i = 0; i < as_lines.size(); i++) | 108 for (const auto& line : as_lines) |
| 109 ret.list_value().push_back(Value(origin, as_lines[i])); | 109 ret.list_value().push_back(Value(origin, line)); |
| 110 return ret; | 110 return ret; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Backend for ConvertInputToValue, this takes the extracted string for the | 113 // Backend for ConvertInputToValue, this takes the extracted string for the |
| 114 // input conversion so we can recursively call ourselves to handle the optional | 114 // input conversion so we can recursively call ourselves to handle the optional |
| 115 // "trim" prefix. This original value is also kept for the purposes of throwing | 115 // "trim" prefix. This original value is also kept for the purposes of throwing |
| 116 // errors. | 116 // errors. |
| 117 Value DoConvertInputToValue(const Settings* settings, | 117 Value DoConvertInputToValue(const Settings* settings, |
| 118 const std::string& input, | 118 const std::string& input, |
| 119 const ParseNode* origin, | 119 const ParseNode* origin, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 const ParseNode* origin, | 208 const ParseNode* origin, |
| 209 const Value& input_conversion_value, | 209 const Value& input_conversion_value, |
| 210 Err* err) { | 210 Err* err) { |
| 211 if (input_conversion_value.type() == Value::NONE) | 211 if (input_conversion_value.type() == Value::NONE) |
| 212 return Value(); // Allow null inputs to mean discard the result. | 212 return Value(); // Allow null inputs to mean discard the result. |
| 213 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err)) | 213 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err)) |
| 214 return Value(); | 214 return Value(); |
| 215 return DoConvertInputToValue(settings, input, origin, input_conversion_value, | 215 return DoConvertInputToValue(settings, input, origin, input_conversion_value, |
| 216 input_conversion_value.string_value(), err); | 216 input_conversion_value.string_value(), err); |
| 217 } | 217 } |
| OLD | NEW |