int TrimCommand :: Execute( ALib::CommandLine & cmd ) { GetSkipOptions( cmd ); if ( cmd.HasFlag( FLAG_TRLEAD ) || cmd.HasFlag( FLAG_TRTRAIL ) ) { mTrimLead = cmd.HasFlag( FLAG_TRLEAD ); mTrimTrail = cmd.HasFlag( FLAG_TRTRAIL ); } else { mTrimLead = mTrimTrail = true; } if ( cmd.HasFlag( FLAG_WIDTH ) ) { GetWidths( cmd.GetValue( FLAG_WIDTH ) ); } ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) ); CommaListToIndex( cl, mFields ); IOManager io( cmd ); CSVRow row; while( io.ReadCSV( row ) ) { if ( Skip( row ) ) { continue; } if ( ! Pass( row ) ) { Trim( row ); } io.WriteRow( row ); } return 0; }
void Table::Print(std::ostream& Result)const{ Row_t::const_iterator RowI=DaTable_.begin(),RowEnd=DaTable_.end(); std::vector<size_t> Widths; for(size_t counter=0;RowI!=RowEnd;++counter){ size_t NCols=RowI->size(); Widths= GetWidths(RowI,NCols,VBorders_[counter],Width_); PrintHBorder(NCols,Result,Widths,VBorders_[counter],HBorders_[counter]); //Print the row Col_t::const_iterator ColI=RowI->begin(),ColEnd=RowI->end(); for(size_t counter1=0;ColI!=ColEnd;counter1++){ if(VBorders_[counter][counter1]!='\0') Result<<VBorders_[counter][counter1]; Result<<ColI->PrintOut(Widths[counter1]); ++ColI; if(ColI==ColEnd){//Print right VBorder if(VBorders_[counter][counter1+1]!='\0') Result<<VBorders_[counter][counter1+1]; } } Result<<std::endl; ++RowI; if(RowI==RowEnd)//Print bottom HBorder PrintHBorder(NCols,Result,Widths,VBorders_[counter],HBorders_[counter+1]); } }