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 <iostream> | 5 #include <iostream> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value()); | 60 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value()); |
61 if (!EnsureStringIsInOutputDir( | 61 if (!EnsureStringIsInOutputDir( |
62 scope->settings()->build_settings()->build_dir(), | 62 scope->settings()->build_settings()->build_dir(), |
63 source_file.value(), args[0].origin(), err)) | 63 source_file.value(), args[0].origin(), err)) |
64 return Value(); | 64 return Value(); |
65 | 65 |
66 // Compute output. | 66 // Compute output. |
67 std::ostringstream contents; | 67 std::ostringstream contents; |
68 if (args[1].type() == Value::LIST) { | 68 if (args[1].type() == Value::LIST) { |
69 const std::vector<Value>& list = args[1].list_value(); | 69 const std::vector<Value>& list = args[1].list_value(); |
70 for (size_t i = 0; i < list.size(); i++) | 70 for (const auto& cur : list) |
71 contents << list[i].ToString(false) << std::endl; | 71 contents << cur.ToString(false) << std::endl; |
72 } else { | 72 } else { |
73 contents << args[1].ToString(false); | 73 contents << args[1].ToString(false); |
74 } | 74 } |
75 const std::string& new_contents = contents.str(); | 75 const std::string& new_contents = contents.str(); |
76 base::FilePath file_path = | 76 base::FilePath file_path = |
77 scope->settings()->build_settings()->GetFullPath(source_file); | 77 scope->settings()->build_settings()->GetFullPath(source_file); |
78 | 78 |
79 // Make sure we're not replacing the same contents. | 79 // Make sure we're not replacing the same contents. |
80 std::string existing_contents; | 80 std::string existing_contents; |
81 if (base::ReadFileToString(file_path, &existing_contents) && | 81 if (base::ReadFileToString(file_path, &existing_contents) && |
(...skipping 11 matching lines...) Expand all Loading... |
93 if (base::WriteFile(file_path, new_contents.c_str(), int_size) | 93 if (base::WriteFile(file_path, new_contents.c_str(), int_size) |
94 != int_size) { | 94 != int_size) { |
95 *err = Err(function->function(), "Unable to write file.", | 95 *err = Err(function->function(), "Unable to write file.", |
96 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); | 96 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); |
97 return Value(); | 97 return Value(); |
98 } | 98 } |
99 return Value(); | 99 return Value(); |
100 } | 100 } |
101 | 101 |
102 } // namespace functions | 102 } // namespace functions |
OLD | NEW |