* Returns true, if firstRow seems to be a header row * @param firstRow The row to be checked. */
| 506 | * @param firstRow The row to be checked. |
| 507 | */ |
| 508 | bool Helper::guessHasHeader(std::vector<std::string> firstRow) { |
| 509 | int cols = firstRow.size(); |
| 510 | for( int c = 0; c < cols; ++c ) { |
| 511 | // Number in first row => NO HEADER |
| 512 | try { |
| 513 | (void)std::stod(firstRow[c]); |
| 514 | return false; |
| 515 | } catch( const std::exception& ) { |
| 516 | // intentionally left empty as we use lexical_cast() to check if its numeric |
| 517 | } |
| 518 | // E-Mail in first row => NO HEADER |
| 519 | if( isEmailAddress(firstRow[c]) ) { |
| 520 | return false; |
| 521 | } |
| 522 | // Something looks like a date string => NO HEADER |
| 523 | if( isSomeDate(firstRow[c]) ) { |
| 524 | return false; |
| 525 | } |
| 526 | // Seems to be a URL => NO HEADER |
| 527 | if( firstRow[c].find("://") != std::string::npos ) { |
| 528 | return false; |
| 529 | } |
| 530 | // Contains some other 'strange' characters => NO HEADER |
| 531 | if( firstRow[c].find_first_of("{}*?!,.;\"'§$%&/\\=+") != std::string::npos ) { |
| 532 | return false; |
| 533 | } |
| 534 | // Cell is empty string => NO HEADER |
| 535 | if( firstRow[c] == "" ) { |
| 536 | return false; |
| 537 | } |
| 538 | } |
| 539 | return true; |
| 540 | } |
| 541 | bool Helper::isEmailAddress(const std::string& email) { |
| 542 | const std::regex pattern ("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+"); |
| 543 | return std::regex_match(email, pattern); |