RowsByStringIndex returns the list of *our indexes* whose row in the table has given string value in given column index (de-reference our indexes to get actual row). if contains, only checks if row contains string; if ignoreCase, ignores case. Use named args for greater clarity.
(colIndex int, str string, contains, ignoreCase bool)
| 466 | // if contains, only checks if row contains string; if ignoreCase, ignores case. |
| 467 | // Use named args for greater clarity. |
| 468 | func (ix *IndexView) RowsByStringIndex(colIndex int, str string, contains, ignoreCase bool) []int { |
| 469 | dt := ix.Table |
| 470 | col := dt.Columns[colIndex] |
| 471 | lowstr := strings.ToLower(str) |
| 472 | var idxs []int |
| 473 | for idx, srw := range ix.Indexes { |
| 474 | val := col.String1D(srw) |
| 475 | has := false |
| 476 | switch { |
| 477 | case contains && ignoreCase: |
| 478 | has = strings.Contains(strings.ToLower(val), lowstr) |
| 479 | case contains: |
| 480 | has = strings.Contains(val, str) |
| 481 | case ignoreCase: |
| 482 | has = strings.EqualFold(val, str) |
| 483 | default: |
| 484 | has = (val == str) |
| 485 | } |
| 486 | if has { |
| 487 | idxs = append(idxs, idx) |
| 488 | } |
| 489 | } |
| 490 | return idxs |
| 491 | } |
| 492 | |
| 493 | // RowsByString returns the list of *our indexes* whose row in the table has |
| 494 | // given string value in given column name (de-reference our indexes to get actual row). |
no test coverage detected