RowsByStringIndex returns the list of rows that have given string value in given column index. if contains, only checks if row contains string; if ignoreCase, ignores case. Use named args for greater clarity.
(column int, str string, contains, ignoreCase bool)
| 400 | // if contains, only checks if row contains string; if ignoreCase, ignores case. |
| 401 | // Use named args for greater clarity. |
| 402 | func (dt *Table) RowsByStringIndex(column int, str string, contains, ignoreCase bool) []int { |
| 403 | col := dt.Columns[column] |
| 404 | lowstr := strings.ToLower(str) |
| 405 | var idxs []int |
| 406 | for i := 0; i < dt.Rows; i++ { |
| 407 | val := col.String1D(i) |
| 408 | has := false |
| 409 | switch { |
| 410 | case contains && ignoreCase: |
| 411 | has = strings.Contains(strings.ToLower(val), lowstr) |
| 412 | case contains: |
| 413 | has = strings.Contains(val, str) |
| 414 | case ignoreCase: |
| 415 | has = strings.EqualFold(val, str) |
| 416 | default: |
| 417 | has = (val == str) |
| 418 | } |
| 419 | if has { |
| 420 | idxs = append(idxs, i) |
| 421 | } |
| 422 | } |
| 423 | return idxs |
| 424 | } |
| 425 | |
| 426 | // RowsByString returns the list of rows that have given |
| 427 | // string value in given column name. returns nil if name invalid -- see also Try. |
no test coverage detected