Column returns the values of the column whose header matches name case-insensitively (trimming surrounding whitespace), with empty and whitespace-only cells dropped, and whether such a column exists.
(name string)
| 109 | // case-insensitively (trimming surrounding whitespace), with empty and |
| 110 | // whitespace-only cells dropped, and whether such a column exists. |
| 111 | func (t *Table) Column(name string) ([]string, bool) { |
| 112 | var header string |
| 113 | found := false |
| 114 | for _, h := range t.Header { |
| 115 | if strings.EqualFold(strings.TrimSpace(h), strings.TrimSpace(name)) { |
| 116 | header = h |
| 117 | found = true |
| 118 | break |
| 119 | } |
| 120 | } |
| 121 | if !found { |
| 122 | return nil, false |
| 123 | } |
| 124 | |
| 125 | values := make([]string, 0, len(t.Rows)) |
| 126 | for _, row := range t.Rows { |
| 127 | if v := strings.TrimSpace(row[header]); v != "" { |
| 128 | values = append(values, v) |
| 129 | } |
| 130 | } |
| 131 | return values, true |
| 132 | } |
| 133 | |
| 134 | // decode normalizes the input to UTF-8, using the BOM (if any) to detect |
| 135 | // UTF-16; defaults to UTF-8 when no BOM is present, stripping a UTF-8 BOM. |
no outgoing calls