summaryrefslogtreecommitdiff
path: root/lib/inifile
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-07-25 23:28:17 -0700
committerOri Bernstein <ori@eigenstate.org>2016-07-25 23:37:49 -0700
commit359f5e7e727145aeebae62563afbbe031257ea21 (patch)
treedab5ae495199137db37b797e76ab78fe7533a4ca /lib/inifile
parentb24fd14c329aa00b0d9703864f875258164216c4 (diff)
downloadmc-359f5e7e727145aeebae62563afbbe031257ea21.tar.gz
Allow iterating over sections in a ini file.
Diffstat (limited to 'lib/inifile')
-rw-r--r--lib/inifile/access.myr26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/inifile/access.myr b/lib/inifile/access.myr
index 587e4c7..f43fddc 100644
--- a/lib/inifile/access.myr
+++ b/lib/inifile/access.myr
@@ -4,11 +4,18 @@ use bio
use "types"
pkg inifile =
+ type inisectiter = struct
+ it : std.htkviter((byte[:], byte[:]), byte[:])
+ ;;
+ impl iterable inisectiter -> byte[:]
+
/* key getting/setting */
const get : (ini : inifile#, sect : byte[:], key : byte[:] -> std.option(byte[:]))
const getv : (ini : inifile#, sect : byte[:], key : byte[:], val : byte[:] -> byte[:])
const has : (ini : inifile#, sect : byte[:], key : byte[:] -> bool)
const put : (ini : inifile#, sect : byte[:], key : byte[:], val : byte[:] -> void)
+
+ const bysection : (ini : inifile# -> inisectiter)
;;
const get = {ini, sect, key
@@ -33,3 +40,22 @@ const put = {ini, sect, key, val
std.htput(ini.elts, (sect, key), std.sldup(val))
}
+const bysection = {ini
+ -> [.it=std.htbykeyvals(ini.elts)]
+}
+
+impl iterable inisectiter -> byte[:] =
+ __iternext__ = {itp, valp : byte[:]#
+ var kvp : ((byte[:], byte[:]), byte[:])
+ if __iternext__(&itp.it, &kvp)
+ match kvp
+ | ((s, _), _): valp# = s
+ ;;
+ -> true
+ ;;
+ -> false
+ }
+
+ __iterfin__ = {itp, valp -> void
+ }
+;;