本文整理汇总了C++中CSVRow类的典型用法代码示例。如果您正苦于以下问题:C++ CSVRow类的具体用法?C++ CSVRow怎么用?C++ CSVRow使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSVRow类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecordSizes
void SummaryCommand :: RecordSizes( const CSVRow & row, SizeMap & sm ) {
for ( unsigned int i = 0; i < row.size(); i++ ) {
int sz = row[i].size();
SizeMap::iterator pos = sm.find( i );
if ( pos == sm.end() ) {
sm[ i ] = std::make_pair( INT_MAX, 0 );
}
sm[i].first = std::min( sm[i].first, sz );
sm[i].second = std::max( sm[i].second, sz );
}
}
示例2: read
void CSVIO::read(std::vector<std::vector<double> >& out){
CSVRow row;
std::vector<string> rowStr;
row.read(ifs);
rowStr = row.getData();
std::vector<double> tVec(rowStr.size());
int rowindex = 0;
while(!ifs.fail() && !ifs.eof() && (rowindex < nrow)){
row.read(ifs);
rowStr = row.getData();
for(int i = 0; i < rowStr.size(); i++){
tVec[i] = std::stof(rowStr.at(i));
}
out.push_back(tVec);
++rowindex;
rowStr.clear();
}
}
示例3: AddRow
void AsciiTableCommand :: AddRow( const CSVRow & row ) {
unsigned int n = row.size();
while( mWidths.size() < n ) {
mWidths.push_back( 0 );
}
for ( unsigned int i = 0; i < n ; i++ ) {
if ( mWidths[i] < row[i].size() ) {
mWidths[i] = row[i].size();
}
}
mRows.push_back( row );
}
示例4: Execute
int TruncPadBase :: Execute( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
string ps = cmd.GetValue( FLAG_PAD );
ALib::CommaList padding( ps );
unsigned int ncols = padding.Size();
bool ncolspec = false; // use explicit size or not
if ( ncols == 0 || cmd.HasFlag( FLAG_NUM ) ) {
if ( ! cmd.HasFlag( FLAG_NUM ) ) {
CSVTHROW( "Need -n flag to specify field count" );
}
ncolspec = true;
string nv = cmd.GetValue( FLAG_NUM );
if ( ALib::ToInteger( nv, "-n flag needs integer value" ) < 0 ) {
CSVTHROW( FLAG_NUM << " needs value greater or equal to zero" );
}
ncols = ALib::ToInteger( nv );
}
IOManager io( cmd );
CSVRow row;
while( io.ReadCSV( row ) ) {
if ( Skip( io, row ) ) {
continue;
}
if ( ! Pass( io, row ) ) {
unsigned int nc = ncolspec ? ncols : row.size() + padding.Size();
ProcessRow( row, nc, padding );
}
io.WriteRow( row );
}
return 0;
}
示例5: MakeKey
string JoinCommand :: MakeKey( const CSVRow & row, bool first ) {
string key;
for ( unsigned int i = 0; i < mJoinSpecs.size(); i++ ) {
unsigned int col = first ? mJoinSpecs[i].first
: mJoinSpecs[i].second;
if ( col >= row.size() ) {
continue;
}
key += mIgnoreCase ? ALib::Upper( row[col] ) : row[col];
key += '\0'; // key element separator
}
return key;
}
示例6: CallOnFields
int CallCommand :: CallOnFields( CSVRow & row, char * buffer ) {
string fields;
int fc = 0;
for ( unsigned int i = 0; i < row.size(); i++ ) {
if ( mFields.size() == 0 || ALib::Contains( mFields, i ) ) {
fields += row[i];
fields += '\0';
fc++;
}
}
int ofc = 0;
int rv = mFunc( fc, fields.c_str(), &ofc, buffer, mOutBufSize );
if ( rv == 0 ) {
int pos = 0;
while( ofc-- ) {
string field = ExtractField( buffer, pos );
pos++;
row.push_back( field );
}
}
return rv;
}
示例7: Execute
int FileInfoCommand :: Execute( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
mTwoCols = cmd.HasFlag( FLAG_TWOC );
mBasename = cmd.HasFlag( FLAG_BASEN );
IOManager io( cmd );
CSVRow row;
while( io.ReadCSV( row ) ) {
if ( Skip( io, row ) ) {
continue;
}
if ( Pass( io, row ) ) {
io.WriteRow( row );
continue;
}
string fname = mBasename
? ALib::Filename( io.CurrentFileName() ).Base()
: io.CurrentFileName();
CSVRow outrow;
if ( mTwoCols ) {
outrow.push_back( fname );
outrow.push_back( ALib::Str( io.CurrentLine() ));
}
else {
outrow.push_back( fname + " ("
+ ALib::Str( io.CurrentLine() ) + ")"
);
}
ALib::operator+=( outrow, row );
io.WriteRow( outrow );
}
return 0;
}
示例8: OutputHeadings
void AsciiTableCommand :: OutputHeadings( std::ostream & os,
const CSVRow & row ) {
os << "|";
for ( unsigned int i = 0; i < mWidths.size() ; i++ ) {
if ( i < row.size() ) {
os << " " << ALib::Centre( row[i], mWidths[i] ) << " |";
}
else {
os << " " << ALib::RightPad( "", mWidths[i] ) << " |";
}
}
os << "\n";
os << MakeSep() << "\n";
}
示例9: Exclude
void ExcludeCommand :: Exclude( CSVRow & r ) const {
CSVRow out;
if ( mReverse ) {
std::reverse( r.begin(), r.end() );
}
for ( unsigned int i = 0; i < r.size(); i++ ) {
if ( ! ALib::Contains( mFields, i ) ) {
out.push_back( r.at( i ) );
}
}
if ( mReverse ) {
std::reverse( out.begin(), out.end() );
}
r.swap( out );
}
示例10: MakeFixedOutput
string WriteFixedCommand :: MakeFixedOutput( const CSVRow & row ) {
string s;
for ( unsigned int i = 0; i < mFields.size(); i++ ) {
string val = mFields[i].first > row.size()
? ""
: row[ mFields[i].first - 1 ];
unsigned int width = mFields[i].second;
s += ALib::RightPad( val, width );
}
return s;
}
示例11: OutputRow
void AsciiTableCommand :: OutputRow( std::ostream & os, const CSVRow & row ) {
os << "|";
for ( unsigned int i = 0; i < mWidths.size() ; i++ ) {
if ( i < row.size() ) {
if ( ALib::Contains( mRightAlign, i ) ) {
os << " " << ALib::LeftPad( row[i], mWidths[i] ) << " |";
}
else {
os << " " << ALib::RightPad( row[i], mWidths[i] ) << " |";
}
}
else {
os << " " << ALib::RightPad( "", mWidths[i] ) << " |";
}
}
os << "\n";
}
示例12: CSVTHROW
void ShuffleCommand ::ShuffleFields( CSVRow & row ) {
std::vector <string> f;
for( unsigned int i = 0; i < mFields.size(); i++ ) {
unsigned int fi = mFields[i];
if ( fi >= row.size() ) {
CSVTHROW( "Invalid field index: " << fi + 1 );
}
else {
f.push_back( row[fi] );
}
}
std::random_shuffle( f.begin(), f.end() );
unsigned int ri = 0;
for( unsigned int i = 0; i < mFields.size(); i++ ) {
unsigned int fi = mFields[i];
row[fi] = f[ri++];
}
}
示例13: HandleSpecialChars
void TemplateCommand :: HandleSpecialChars( const string & tplate,
char c, unsigned int & pos,
const CSVRow & row,
string & out ) {
char t = tplate[ pos++ ];
if ( c == '\\' ) {
switch( t ) {
case '\n':
case '\r': CSVTHROW( "Invalid escape at end of line" );
case 'n': out += '\n'; break;
case 't': out += '\t'; break;
default: out += t;
}
}
else { // its a brace
string ns;
while( t != POUTRO) {
if ( t == '\n' || t == '\r' ) {
CSVTHROW( "Missing closing brace" );
}
ns += t;
t = tplate[ pos++ ];
}
if( ns.size() && ns[0] == EVALCHR ) { // it's an expression
out += Eval( row, ns );
return;
}
if ( ! ALib::IsInteger( ns ) ) {
CSVTHROW( "Invalid placeholder: " << "{" << ns << "}" );
}
int n = ALib::ToInteger( ns ) - 1; // to zero based
if ( n < 0 ) {
CSVTHROW( "Invalid placeholder: " << "{" << ns << "}" );
}
if ( (unsigned int) n < row.size() ) {
out += row[ n ];
}
}
}
示例14: Trim
void TrimCommand :: Trim( CSVRow & row ) {
for ( unsigned int i = 0; i < row.size(); i++ ) {
if ( mFields.size() == 0 || ALib::Contains( mFields, i ) ) {
if ( mTrimLead && mTrimTrail ) {
row[i] = ALib::Trim( row[i] );
}
else if ( mTrimLead ) {
row[i] = ALib::LTrim( row[i] );
}
else {
row[i] = ALib::RTrim( row[i] );
}
}
if ( mWidths.size() ) {
if ( mFields.size() == 0 || ALib::Contains( mFields, i ) ) {
Chop( row, i );
}
}
}
}
示例15: CreateValues
string SQLInsertCommand :: CreateValues( const CSVRow & row ) const {
string vals = "";
for ( unsigned int i = 0; i < DataCols().size(); i++ ) {
unsigned int fi = DataCols().at(i).mField;
if ( fi >= row.size() ) {
CSVTHROW( "Required field " << fi + 1 << " missing from input" );
}
if ( vals != "" ) {
vals += ", ";
}
string field = EmptyToNull( row[fi] );
vals += ( DoSQLQuote( i ) && ! NoNullQuote( field ) )
? ALib::SQuote( ALib::SQLQuote( field ) )
: field;
}
return " VALUES( " + vals + ")";
}