OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ |
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 | 14 |
15 namespace password_manager { | 15 namespace password_manager { |
16 | 16 |
17 typedef std::map<std::string, std::string> ColumnNameToValueMap; | |
Garrett Casto
2015/06/26 21:13:48
For some reason I forgot that this would be used i
xunlu
2015/06/30 23:06:09
Done.
| |
18 | |
17 // Reads tabular data from CSV (Comma Separated Values) format as defined in RFC | 19 // Reads tabular data from CSV (Comma Separated Values) format as defined in RFC |
18 // 4180, with the following limitations/relaxations: | 20 // 4180, with the following limitations/relaxations: |
19 // * The input should be UTF-8 encoded. No code points should be escaped. | 21 // * The input should be UTF-8 encoded. No code points should be escaped. |
20 // * The first line must be a header that contains the column names. | 22 // * The first line must be a header that contains the column names. |
21 // * Records may be separated by either LF or CRLF sequences. Each CRLF will | 23 // * Records may be separated by either LF or CRLF sequences. Each CRLF will |
22 // be converted to LF characters inside quotes. | 24 // be converted to LF characters inside quotes. |
23 // * Inconsistent number of fields within records is handled gracefully. Extra | 25 // * Inconsistent number of fields within records is handled gracefully. Extra |
24 // fields are ignored. Missing fields will have no corresponding key-value | 26 // fields are ignored. Missing fields will have no corresponding key-value |
25 // pair in the record's ColumnNameToValueMap. | 27 // pair in the record's ColumnNameToValueMap. |
26 // * Repeated columns of the same name are not supported (the last value will | 28 // * Repeated columns of the same name are not supported (the last value will |
27 // be preserved). | 29 // be preserved). |
28 // | 30 // |
29 // The CSV representation of the data will be read from |csv|. The first line of | 31 // The CSV representation of the data will be read from |csv|. The first line of |
30 // the file should be a header to extract |column_names| from. From each | 32 // the file should be a header to extract |column_names| from. From each |
31 // subsequent line, the extracted values are put into a map mapping column names | 33 // subsequent line, the extracted values are put into a map mapping column names |
32 // to the value of the corresponding field, and inserted into |records|. Both | 34 // to the value of the corresponding field, and inserted into |records|. Both |
33 // |column_names| and |records| will be overwritten. Returns false if parsing | 35 // |column_names| and |records| will be overwritten. Returns false if parsing |
34 // failed due to a syntax error. | 36 // failed due to a syntax error. |
35 bool ReadCSV(base::StringPiece csv, | 37 bool ReadCSV(base::StringPiece csv, |
36 std::vector<std::string>* column_names, | 38 std::vector<std::string>* column_names, |
37 std::vector<std::map<std::string, std::string>>* records); | 39 std::vector<std::map<std::string, std::string>>* records); |
Garrett Casto
2015/06/26 21:13:48
|records| should be a vector of ColumnNameToValueM
xunlu
2015/06/30 23:06:09
Done.
| |
38 | 40 |
39 } // namespace password_manager | 41 } // namespace password_manager |
40 | 42 |
41 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ | 43 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ |
OLD | NEW |