ffead.server.doc
CsvFileReader.cpp
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * CsvFileReader.cpp
18  *
19  * Created on: 29-Jan-2013
20  * Author: sumeetc
21  */
22 
23 #include "CsvFileReader.h"
24 
25 CsvFileReader::CsvFileReader() {
26  // TODO Auto-generated constructor stub
27 
28 }
29 
30 CsvFileReader::~CsvFileReader() {
31  // TODO Auto-generated destructor stub
32 }
33 
34 strVecVec CsvFileReader::getRows(string filepath)
35 {
36  strVecVec all;
37  string line;
38  if (filepath=="")
39  {
40  return all;
41  }
42  ifstream myfile (&filepath[0],ios::in | ios::binary);
43  if (myfile.is_open())
44  {
45  while(getline(myfile,line,'\n'))
46  {
47  if(line!="")
48  {
49  StringUtil::replaceAll(line,"\n","");
50  StringUtil::replaceAll(line,"\r","");
51  vector<string> vemp = StringUtil::split(line, (","));
52  if(vemp.size()>0)
53  all.push_back(vemp);
54  }
55  }
56  myfile.close();
57  }
58  return all;
59 }