shithub: mc

ref: 90dc5f51483723b1cd8604d749ef3158d55c21ca
dir: /lib/inifile/access.myr/

View raw version
use std
use bio

use "types"

pkg inifile =
	/* 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 get = {ini, sect, key
	-> std.htget(ini.elts, (sect, key))
}

const getv = {ini, sect, key, val
	-> std.htgetv(ini.elts, (sect, key), val)
}

const has = {ini, sect, key
	-> std.hthas(ini.elts, (sect, key))
}

const put = {ini, sect, key, val
	if std.hthas(ini.elts, (sect, key))
		std.slfree(std.htgetv(ini.elts, (sect, key), ""))
	else
		sect = std.sldup(sect)
		key = std.sldup(key)
	;;
	std.htput(ini.elts, (sect, key), std.sldup(val))
}