Skip to content

Commit

Permalink
test 4
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswi committed Apr 5, 2011
1 parent 2c9182b commit 91bb2ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sample2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
teja,teja1,teja2
teja3,teja4,teja5
24 changes: 23 additions & 1 deletion src/FileRecordsReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ vector< vector <string > > myRecords;
vector< string> FileRecordsReader::getRecord(const string& myRecord)
{
vector <string > record;
record.push_back(myRecord);
string delim (",");
tokenize(myRecord, record ,delim );
return record;
}
void FileRecordsReader::tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = ",")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);

while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}


6 changes: 5 additions & 1 deletion src/FileRecordsReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ class FileRecordsReader : public RecordsReader
public:
FileRecordsReader( string fileName , int numOfCol ) throw( exception ) ;
virtual vector < vector<string> > getRecords() ;
virtual vector< string > getRecord( const string& myRecord);
virtual vector< string > getRecord(const string& myRecord);
virtual ~FileRecordsReader();
private:
ifstream myStream;
int myCol;
void tokenize(const string& str,
vector<string>& tokens,
const string& delimiters );


};
#endif

0 comments on commit 91bb2ff

Please sign in to comment.