summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-09-24 17:43:27 -0700
committerOri Bernstein <ori@markovcorp.com>2018-09-24 17:43:43 -0700
commit68168e2f7b835bd63359c3d516b458ff687dba01 (patch)
treefda38e9f61ffeac29fe38b0e03085d2e56552e0f
parentba9519781df047104b22bd2285e2d608253812f1 (diff)
downloadmc-68168e2f7b835bd63359c3d516b458ff687dba01.tar.gz
Add iterator for all section, key, val pairs in inifile.
-rw-r--r--lib/inifile/access.myr23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/inifile/access.myr b/lib/inifile/access.myr
index 49a6476..1af4fad 100644
--- a/lib/inifile/access.myr
+++ b/lib/inifile/access.myr
@@ -8,7 +8,11 @@ pkg inifile =
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 @@ pkg inifile =
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
@@ -45,6 +50,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[:]#
if itp.idx < itp.ini.sects.len