MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / createJsFindSubstring

Method createJsFindSubstring

src/csvtable.cpp:340–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338}
339
340std::string CsvTable::createJsFindSubstring(std::string search, table_index_t startRow, table_index_t startCol, bool caseSensitive) {
341 std::string js = "";
342 js += R"(
343 function get_next_cell(r,c) {
344 ++c;
345 if(c>COLMAX) {
346 c=COLMIN; ++r;
347 }
348 if(r>ROWMAX) {
349 r=ROWMIN;
350 }
351 println("get_next_cell:", r, c);
352 return [r,c];
353 }
354 )";
355 js += "var re = /" + search + "/";
356 if( !caseSensitive ) {
357 js += "i";
358 }
359 js += ";";
360 js += "var start_row = " + std::to_string(startRow) + ";";
361 js += "var start_col = " + std::to_string(startCol) + ";";
362 js += R"(
363 var found_row = -1, found_col = -1;
364 pos = [start_row, start_col];
365 println("Start:",pos[0],pos[1]);
366 outer_loop:
367 do {
368 pos = get_next_cell(pos[0], pos[1]);
369 var cell = getString(pos[0], pos[1]);
370 if( m = cell.match(re) ) {
371 found_row = pos[0];
372 found_col = pos[1];
373 break outer_loop;
374 }
375 } while(pos[0] != start_row || pos[1] != start_col);
376 __storeInts(found_row, found_col);
377 )";
378 return js;
379}
380
381
382/*

Callers

nothing calls this directly

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected