Chromium Code Reviews| Index: components/password_manager/core/browser/import/csv_reader.h |
| diff --git a/components/password_manager/core/browser/import/csv_reader.h b/components/password_manager/core/browser/import/csv_reader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be5428239a4f886c35b1e8a7e2241c2f09bbedc7 |
| --- /dev/null |
| +++ b/components/password_manager/core/browser/import/csv_reader.h |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ |
| +#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/strings/string_piece.h" |
| + |
| +namespace password_manager { |
| + |
| +// Reads tabular data from CSV (Comma Separated Values) format as defined in RFC |
| +// 4180, with the following limitations/relaxations: |
| +// * The input should be UTF-8 encoded. No code points should be escaped. |
| +// * The first line must be a header that contains the column names. |
| +// * Records may be separated by either LF or CRLF sequences. Each CRLF will |
| +// be converted to LF characters inside quotes. |
| +// * Inconsistent number of fields within records is handled gracefully. Extra |
| +// fields are ignored. Missing fields will have no corresponding key-value |
| +// pair in the record's ColumnNameToValueMap. |
| +class CSVReader { |
|
vabr (Chromium)
2014/09/25 14:44:27
Why a class and not just a helper function?
engedy
2014/11/06 14:55:39
Same reason as for CSVWriter: for consistency with
vabr (Chromium)
2014/11/06 16:16:02
Again, JSONReader actually uses the non-static par
engedy
2014/11/07 16:26:11
Please see my response at CSVWriter.
|
| + public: |
| + typedef std::map<std::string, std::string> ColumnNameToValueMap; |
| + |
| + // Reads and parses the CSV representation of the data from |csv|. The first |
| + // line of the file should be a header to extract |column_names| from. For |
| + // each subsequent line, the extracted values are put into a map mapping |
| + // column names to the value of the corresponding field, and inserted into |
| + // |records|. |
|
vabr (Chromium)
2014/09/25 14:44:28
nit: I suggest explicitly stating that both vector
engedy
2014/11/06 14:55:39
Done.
|
| + static bool Read(base::StringPiece csv, |
|
vabr (Chromium)
2014/09/25 14:44:27
Please comment on the return value.
engedy
2014/11/06 14:55:39
Done.
|
| + std::vector<std::string>* column_names, |
| + std::vector<ColumnNameToValueMap>* records); |
| + |
| + private: |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(CSVReader); |
| +}; |
| + |
| +} // namespace password_manager |
| + |
| +#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_ |