------------------------------------------------------------------------------
| 493 | |
| 494 | //------------------------------------------------------------------------------ |
| 495 | void vtkBiomTableReader::ParseColumns() |
| 496 | { |
| 497 | // find "columns": |
| 498 | size_t pos_start = this->FileContents.find("\"columns\":"); |
| 499 | if (pos_start == std::string::npos) |
| 500 | { |
| 501 | vtkErrorMacro(<< "columns not found in input file"); |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | for (int currentCol = 1; currentCol < this->NumberOfColumns + 1; ++currentCol) |
| 506 | { |
| 507 | // find id for this column |
| 508 | size_t pos_column_1 = this->FileContents.find("\"id\":", pos_start); |
| 509 | if (pos_column_1 == std::string::npos) |
| 510 | { |
| 511 | vtkErrorMacro(<< "columns field not formatted properly"); |
| 512 | return; |
| 513 | } |
| 514 | size_t pos_column_2 = this->FileContents.find("\", \"metadata\":", pos_column_1); |
| 515 | if (pos_column_2 == std::string::npos) |
| 516 | { |
| 517 | vtkErrorMacro(<< "columns field not formatted properly"); |
| 518 | return; |
| 519 | } |
| 520 | std::string name = this->FileContents.substr(pos_column_1 + 5, pos_column_2 - pos_column_1 - 5); |
| 521 | // remove quotes |
| 522 | name.erase(remove(name.begin(), name.end(), '\"'), name.end()); |
| 523 | // trim whitespace |
| 524 | const size_t beginStr = name.find_first_not_of(" \t"); |
| 525 | const size_t endStr = name.find_last_not_of(" \t"); |
| 526 | const size_t range = endStr - beginStr + 1; |
| 527 | name = name.substr(beginStr, range); |
| 528 | this->GetOutput()->GetColumn(currentCol)->SetName(name.c_str()); |
| 529 | pos_start = pos_column_2; |
| 530 | |
| 531 | // this is where we would capture the metadata for this column |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | //------------------------------------------------------------------------------ |
| 536 | void vtkBiomTableReader::ParseRows() |