lib/Str/Brk.ps1
function Brk-At ($s,$pos,$sepLen){Trim(Left $s ($pos-1)); Trim(Mid $s ($pos+$Seplen))} function Brk-Spc ($s,[switch]$rev){Brk $s -rev:$rev} function Brk-Spc1 ($s,[switch]$rev){Brk-1 $s -rev:$rev} function Brk-Spc2 ($s,[switch]$rev){Brk-2 $s -rev:$rev} function Brk-Dot ($s,[switch]$rev){Brk $s '.' -rev:$rev} function Brk-Dot1 ($s,[switch]$rev){Brk-1 $s '.' -rev:$rev} function Brk-Dot2 ($s,[switch]$rev){Brk-2 $s '.' -rev:$rev} function Brk ($s,$sep=' ',[switch]$rev){$p=Instr($s=Trim $s) $sep -rev:$rev;if($p-eq-1){throw "no sep[$sep] in s[$s]"};Brk-At $s $p (Len $sep)} function Brk-1 ($s,$sep=' ',[switch]$rev){$p=Instr($s=Trim $s) $sep -rev:$rev;if($p-eq0){$s,""}else{Brk-At $s $p (Len $sep)}} function Brk-2 ($s,$sep=' ',[switch]$rev){$p=Instr($s=Trim $s) $sep -rev:$rev;if($p-eq0){"",$s}else{Brk-At $s $p (Len $sep)}} function Brk-Quote($quote){ switch(len $quote) { 1 {return $quote,$quote} 2 {return(Fst-Chr $quote),(Las-Chr $quote)} 0 {return '',''} } if(!(Has-Sub $quote '*')){throw "`$quote[$quote] should have len = 0 1 2 or has *"} Brk $quote "*" } |