ref: 68168e2f7b835bd63359c3d516b458ff687dba01
parent: ba9519781df047104b22bd2285e2d608253812f1
author: Ori Bernstein <ori@markovcorp.com>
date: Mon Sep 24 13:43:27 EDT 2018
Add iterator for all section, key, val pairs in inifile.
--- a/lib/inifile/access.myr
+++ b/lib/inifile/access.myr
@@ -8,7 +8,11 @@
ini : inifile#
idx : int
;;
+ type inikviter = struct
+ iter : std.htkviter((byte[:], byte[:]), byte[:])
+ ;;
impl iterable inisectiter -> byte[:]
+ impl iterable inikviter -> (byte[:], byte[:], byte[:])
/* key getting/setting */
const get : (ini : inifile#, sect : byte[:], key : byte[:] -> std.option(byte[:]))
@@ -17,6 +21,7 @@
const put : (ini : inifile#, sect : byte[:], key : byte[:], val : byte[:] -> void)
const bysection : (ini : inifile# -> inisectiter)
+ const bykeyval : (ini : inifile# -> inikviter)
;;
const get = {ini, sect, key
@@ -44,6 +49,24 @@
const bysection = {ini
-> [.ini=ini, .idx=0]
}
+
+const bykeyval = {ini
+ -> [.iter = std.byhtkeyvals(ini.elts)]
+}
+
+
+impl iterable inikviter -> (byte[:], byte[:], byte[:]) =
+ __iternext__ = {itp, valp
+ var s, k, v, p, r
+ r = __iternext__(&itp.iter, &p)
+ ((s, k), v) = p
+ valp# = (s, k, v)
+ -> r
+ }
+
+ __iterfin__ = {itp, valp
+ }
+;;
impl iterable inisectiter -> byte[:] =
__iternext__ = {itp, valp : byte[:]#