OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/system/name_value_pairs_parser.h" | 5 #include "chrome/browser/chromeos/system/name_value_pairs_parser.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/string_tokenizer.h" | |
14 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/strings/string_tokenizer.h" |
15 | 15 |
16 namespace chromeos { // NOLINT | 16 namespace chromeos { // NOLINT |
17 namespace system { | 17 namespace system { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kQuoteChars[] = "\""; | 21 const char kQuoteChars[] = "\""; |
22 const char kTrimChars[] = "\" "; | 22 const char kTrimChars[] = "\" "; |
23 | 23 |
24 bool GetToolOutput(int argc, const char* argv[], std::string& output) { | 24 bool GetToolOutput(int argc, const char* argv[], std::string& output) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return ParseNameValuePairsWithComments(in_string, eq, delim, ""); | 63 return ParseNameValuePairsWithComments(in_string, eq, delim, ""); |
64 } | 64 } |
65 | 65 |
66 bool NameValuePairsParser::ParseNameValuePairsWithComments( | 66 bool NameValuePairsParser::ParseNameValuePairsWithComments( |
67 const std::string& in_string, | 67 const std::string& in_string, |
68 const std::string& eq, | 68 const std::string& eq, |
69 const std::string& delim, | 69 const std::string& delim, |
70 const std::string& comment_delim) { | 70 const std::string& comment_delim) { |
71 bool all_valid = true; | 71 bool all_valid = true; |
72 // Set up the pair tokenizer. | 72 // Set up the pair tokenizer. |
73 StringTokenizer pair_toks(in_string, delim); | 73 base::StringTokenizer pair_toks(in_string, delim); |
74 pair_toks.set_quote_chars(kQuoteChars); | 74 pair_toks.set_quote_chars(kQuoteChars); |
75 // Process token pairs. | 75 // Process token pairs. |
76 while (pair_toks.GetNext()) { | 76 while (pair_toks.GetNext()) { |
77 std::string pair(pair_toks.token()); | 77 std::string pair(pair_toks.token()); |
78 // Anything before the first |eq| is the key, anything after is the value. | 78 // Anything before the first |eq| is the key, anything after is the value. |
79 // |eq| must exist. | 79 // |eq| must exist. |
80 size_t eq_pos = pair.find(eq); | 80 size_t eq_pos = pair.find(eq); |
81 if (eq_pos != std::string::npos) { | 81 if (eq_pos != std::string::npos) { |
82 // First |comment_delim| after |eq_pos| starts the comment. | 82 // First |comment_delim| after |eq_pos| starts the comment. |
83 // A value of |std::string::npos| means that the value spans to the end | 83 // A value of |std::string::npos| means that the value spans to the end |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 std::string output_string; | 139 std::string output_string; |
140 if (!GetToolOutput(argc, argv, output_string)) | 140 if (!GetToolOutput(argc, argv, output_string)) |
141 return false; | 141 return false; |
142 | 142 |
143 return ParseNameValuePairsWithComments( | 143 return ParseNameValuePairsWithComments( |
144 output_string, eq, delim, comment_delim); | 144 output_string, eq, delim, comment_delim); |
145 } | 145 } |
146 | 146 |
147 } // namespace system | 147 } // namespace system |
148 } // namespace chromeos | 148 } // namespace chromeos |
OLD | NEW |