| 1133 | |
| 1134 | |
| 1135 | std::string CsvTable::vec2string(const std::vector<std::string> &line, CsvDefinition definition) { |
| 1136 | std::stringstream ret; |
| 1137 | size_t cellLength; |
| 1138 | for( size_t i = 0; i != line.size(); ++i) { |
| 1139 | if( toBeQuoted(line.at(i), definition ) ) { |
| 1140 | cellLength = line.at(i).length(); |
| 1141 | ret << definition.quote; |
| 1142 | for( size_t j = 0; j < cellLength; ++j ) { |
| 1143 | if( line.at(i).at(j) == definition.quote ) { |
| 1144 | ret << definition.quote; |
| 1145 | } |
| 1146 | ret << line.at(i).at(j); |
| 1147 | } |
| 1148 | ret << definition.quote; |
| 1149 | } else { |
| 1150 | ret << line.at(i); |
| 1151 | } |
| 1152 | if( i < line.size()-1 ) { |
| 1153 | ret << definition.delimiter; |
| 1154 | } |
| 1155 | } |
| 1156 | return ret.str(); |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | // returns true if field has to be quoted |