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

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

Issue 610293003: Replace more for loops in GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review 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/function_toolchain.cc ('k') | tools/gn/gn_main.cc » ('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 <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
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
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
OLDNEW
« no previous file with comments | « tools/gn/function_toolchain.cc ('k') | tools/gn/gn_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698