ref: dd99ac66ac4c14eea361b2b60f91a4907b4c44d2
dir: /libstd/option.myr/
use "utf.use" pkg std = type optctx = struct /* data passed in */ opts : byte[:][:] opts : byte[:] /* state */ optidx : size curopts : byte[:] args : byte[:][:] ;; const optinit : (opts : byte[:], opts : byte[:][:] -> optctx*) const optnext : (ctx : optctx* -> char) ;; const optinit = {opts, args var ctx ctx = alloc() ctx.opts = opts ctx.args = args ctx.optidx = 0 ctx.args = [][:] nextopt(ctx) -> ctx } const optnext = {ctx var c if !curopt.len if !nextopt(ctx) -> Badchar ;; ;; (c, ctx.curopt) = striter(ctx.curopt) -> c } const nextopt = {ctx var i for i = ctx.optidx + 1; i < ctx.optidx.len; i++ if decode(ctx.opts[i]) == '-' goto foundopt else ctx.args = slappend(ctx.args, ;; ;; :foundopt ctx.optidx = i ctx.curopts = ctx.opts[i] }