| 216 | string na_value_; |
| 217 | |
| 218 | void ExtractFields(OpKernelContext* ctx, StringPiece input, |
| 219 | std::vector<string>* result) { |
| 220 | int64 current_idx = 0; |
| 221 | int64 num_fields_parsed = 0; |
| 222 | int64 selector_idx = 0; // Keep track of index into select_cols |
| 223 | |
| 224 | if (!input.empty()) { |
| 225 | while (static_cast<size_t>(current_idx) < input.size()) { |
| 226 | if (input[current_idx] == '\n' || input[current_idx] == '\r') { |
| 227 | current_idx++; |
| 228 | continue; |
| 229 | } |
| 230 | |
| 231 | bool quoted = false; |
| 232 | bool include = |
| 233 | (select_all_cols_ || select_cols_[selector_idx] == |
| 234 | static_cast<size_t>(num_fields_parsed)); |
| 235 | |
| 236 | if (use_quote_delim_ && input[current_idx] == '"') { |
| 237 | quoted = true; |
| 238 | current_idx++; |
| 239 | } |
| 240 | |
| 241 | // This is the body of the field; |
| 242 | string field; |
| 243 | if (!quoted) { |
| 244 | while (static_cast<size_t>(current_idx) < input.size() && |
| 245 | input[current_idx] != delim_) { |
| 246 | OP_REQUIRES(ctx, |
| 247 | (!use_quote_delim_ || input[current_idx] != '"') && |
| 248 | input[current_idx] != '\n' && |
| 249 | input[current_idx] != '\r', |
| 250 | errors::InvalidArgument( |
| 251 | "Unquoted fields cannot have quotes/CRLFs inside")); |
| 252 | if (include) field += input[current_idx]; |
| 253 | current_idx++; |
| 254 | } |
| 255 | |
| 256 | // Go to next field or the end |
| 257 | current_idx++; |
| 258 | } else if (use_quote_delim_) { |
| 259 | // Quoted field needs to be ended with '"' and delim or end |
| 260 | while ( |
| 261 | (static_cast<size_t>(current_idx) < input.size() - 1) && |
| 262 | (input[current_idx] != '"' || input[current_idx + 1] != delim_)) { |
| 263 | if (input[current_idx] != '"') { |
| 264 | if (include) field += input[current_idx]; |
| 265 | current_idx++; |
| 266 | } else { |
| 267 | OP_REQUIRES( |
| 268 | ctx, input[current_idx + 1] == '"', |
| 269 | errors::InvalidArgument("Quote inside a string has to be " |
| 270 | "escaped by another quote")); |
| 271 | if (include) field += '"'; |
| 272 | current_idx += 2; |
| 273 | } |
| 274 | } |
| 275 |
nothing calls this directly
no test coverage detected