From b56062ede648745047878fea02d6392de5c90e80 Mon Sep 17 00:00:00 2001
From: Nathan Gass
Date: Mon, 9 Sep 2024 17:33:55 +0200
Subject: add separator argument to all column based methods

---
 it_pipe.class | 20 ++++++++++++--------
 1 file 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")
-- 
cgit v1.2.3