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..1b5fc3857a1b23aba7e32bc877ab6d828a3c1811 |
| --- /dev/null |
| +++ b/components/password_manager/core/browser/import/csv_reader.h |
| @@ -0,0 +1,46 @@ |
| +// 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/basictypes.h" |
|
tfarina
2014/08/06 16:45:12
this can be, in fact, it should be macros.h
engedy
2014/08/08 17:06:13
Done.
|
| +#include "base/strings/string_piece.h" |
|
tfarina
2014/08/06 16:45:12
I bet you can forward declare this:
namespace bas
engedy
2014/08/08 17:06:13
Unfortunately, I think this will not work, as base
|
| + |
| +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 CR or CRLF sequences. Each CRLF will |
| +// be converted to LF characters inside quotes. |
| +// * Inconsistent number of fields within records is handled gracefully. Each |
| +// extracted record will have the same number of values as the number of |
| +// fields in the header line. Extra fields are ignored. Missing fields will |
| +// appear to have an empty value. |
| +class CSVReader { |
| + 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|. |
| + static bool Read(const base::StringPiece& csv, |
|
vasilii
2014/08/06 17:42:17
By value.
engedy
2014/08/08 17:06:13
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_ |