blob: feee4d18c6921499e20973fe8c81ed5c90eb8f24 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
6#include "CsvReader.hpp"
David Monahana8837bf2020-04-16 10:01:56 +01007#include "armnn/utility/StringUtils.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01008
telsoa01c577f2c2018-08-31 09:22:23 +01009#include <boost/tokenizer.hpp>
10
11#include <fstream>
12#include <string>
13#include <vector>
14
15using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
16
17namespace armnnUtils
18{
19
20CsvRow ParseLine(const std::string& csvLine)
21{
22 Tokenizer tokenizer(csvLine);
23 CsvRow entry;
24
25 for (const auto &token : tokenizer)
26 {
David Monahana8837bf2020-04-16 10:01:56 +010027 entry.values.push_back(armnn::stringUtils::StringTrimCopy(token));
telsoa01c577f2c2018-08-31 09:22:23 +010028 }
29 return entry;
30}
31
32std::vector<CsvRow> CsvReader::ParseFile(const std::string& csvFile)
33{
34 std::vector<CsvRow> result;
35
36 std::ifstream in(csvFile.c_str());
37 if (!in.is_open())
38 return result;
39
40 std::string line;
41 while (getline(in, line))
42 {
43 if(!line.empty())
44 {
45 CsvRow entry = ParseLine(line);
46 result.push_back(entry);
47 }
48 }
49 return result;
50}
51
52std::vector<CsvRow> CsvReader::ParseVector(const std::vector<std::string>& csvVector)
53{
54 std::vector<CsvRow> result;
55
56 for (auto const& line: csvVector)
57 {
58 CsvRow entry = ParseLine(line);
59 result.push_back(entry);
60 }
61 return result;
62}
63} // namespace armnnUtils