shithub: mc

ref: 19d7fac9e6210af527ee1e72de4878d3951c41f6
dir: /lib/std/strsplit.myr/

View raw version
use "alloc.use"
use "die.use"
use "extremum.use"
use "option.use"
use "slpush.use"
use "strfind.use"
use "types.use"

pkg std =
	const strsplit	: (s : byte[:], delim : byte[:] -> byte[:][:])
;;

const strsplit = {s, delim
	var last
	var sp

	sp = [][:]
	if s.len == 0
		-> sp
	;;
	last = 0
	while true
		match strfind(s, delim)
		| `Some i:
			sp = slpush(sp, s[:i])
			s = s[i + delim.len:]
		| `None:
			goto donesplit
		;;
	;;
:donesplit
	sp = slpush(sp, s[:])
	-> sp
}