diff options
author | Nathan Gass | 2024-09-09 17:33:55 +0200 |
---|---|---|
committer | Nathan Gass | 2024-09-09 17:36:10 +0200 |
commit | b56062ede648745047878fea02d6392de5c90e80 (patch) | |
tree | 66fe80b54a058e718027a3287d34be11bb9832fe | |
parent | f9a6d22c30938cb73ad2d79c22ce49f37b0fb966 (diff) | |
download | itools-b56062ede648745047878fea02d6392de5c90e80.tar.gz itools-b56062ede648745047878fea02d6392de5c90e80.tar.bz2 itools-b56062ede648745047878fea02d6392de5c90e80.zip |
add separator argument to all column based methods
-rw-r--r-- | it_pipe.class | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/it_pipe.class b/it_pipe.class index 50a1f00..413a7b5 100644 --- a/it_pipe.class +++ b/it_pipe.class @@ -112,24 +112,27 @@ function grep($regexp) /** * Select cols from tab-separated cols in each line and tab-joins them again. Key order relevant. + * @param picks comma separated column numbers to pick + * @param separator split character ["\t"] */ -function cut($picks) +function cut($picks, $separator = "\t") { foreach ($this->lines as $idx => $line) - $this->lines[$idx] = implode("\t", it::filter_keys(explode("\t", $line), $picks, ['reorder' => true])); + $this->lines[$idx] = implode($separator, it::filter_keys(explode($separator, $line), $picks, ['reorder' => true])); return $this; } /** * Swap first two columns + * @param separator split character ["\t"] */ -function swap() +function swap($separator = "\t") { foreach ($this->lines as $idx => $line) { - list($col1, $col2) = explode("\t", $line, 2); - $this->lines[$idx] = "$col2\t$col1"; + list($col1, $col2) = explode($separator, $line, 2); + $this->lines[$idx] = "$col2$separator$col1"; } return $this; @@ -137,12 +140,13 @@ function swap() /** * Return contents of pipe as key->val pair (key must be tab separated). + * @param separator split character ["\t"] */ -function keyval() +function keyval($separator = "\t") { foreach ($this->lines as $line) { - list($key, $val) = explode("\t", $line, 2); + list($key, $val) = explode($separator, $line, 2); $result[$key] = $val; } @@ -169,7 +173,7 @@ function ED() /** * Convert every line into an object with named columns - * @param collist comma separator column name list + * @param collist comma separated column name list * @param separator split character ["\t"] */ function cols($collist, $separator = "\t") |