* Find in cell r,c */
| 383 | * Find in cell r,c |
| 384 | */ |
| 385 | bool CsvTable::findInCell(std::string search, table_index_t r, table_index_t c, bool caseSensitive, bool useRegex) { |
| 386 | std::string lowerSearch; |
| 387 | std::tuple<int, std::string> executeReturn; // for JS search |
| 388 | |
| 389 | if( useRegex ) { |
| 390 | std::string js = ""; |
| 391 | js += "var R = " + std::to_string(r) + "; var C = " + std::to_string(c) + ";"; |
| 392 | js += "var pattern = /" + search + "/"; |
| 393 | if( !caseSensitive ) { |
| 394 | js += "i"; |
| 395 | } |
| 396 | js += ";"; |
| 397 | js += R"( |
| 398 | var found = 0; |
| 399 | var cell = getString(R,C); |
| 400 | if( m = cell.match(pattern) ) { |
| 401 | found = 1; |
| 402 | } |
| 403 | __storeInts(found); |
| 404 | )"; |
| 405 | executeReturn = macro.execute(this, {-1,-1,-1,-1}, js); |
| 406 | if( std::get<0>(executeReturn) == -1 ) { |
| 407 | printf("ERROR: %s\n", std::get<1>(executeReturn).c_str()); |
| 408 | } |
| 409 | std::vector<int> found = Macro::getLastResultInts(); |
| 410 | if( found.size() == 1 && found.at(0) == 1 ) { |
| 411 | return true; |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | if( !caseSensitive ) { |
| 417 | lowerSearch = Utf8CppUtils::utf8::casefold(search); |
| 418 | } |
| 419 | if( caseSensitive ) { |
| 420 | if( |
| 421 | storage.getRow(r).find(search) != std::string::npos && |
| 422 | getCell(r,c).find(search) != std::string::npos |
| 423 | ) { |
| 424 | return true; |
| 425 | } |
| 426 | } else { |
| 427 | if( |
| 428 | Utf8CppUtils::utf8::casefold(storage.getRow(r)).find(lowerSearch) != std::string::npos && |
| 429 | Utf8CppUtils::utf8::casefold(getCell(r,c)).find(lowerSearch) != std::string::npos |
| 430 | ) { |
| 431 | return true; |
| 432 | } |
| 433 | } |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | |
| 438 |