Last active
October 6, 2015 02:38
-
-
Save kgadek/2921556 to your computer and use it in GitHub Desktop.
Erlang: extract *.ini file from *.tgx package and parse it in 12 LOC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_ini(Filename) -> | |
Str = string:tokens(os:cmd(["tar JxOf ", Filename, " settings.conf"]), "\n"), | |
parse_ini(Str, default, []). | |
parse_ini([], _Group, Res) -> Res; | |
parse_ini([Head|Tail], Group, Res) -> | |
[F|R] = Str = string:strip(Head), | |
case F of | |
$# -> parse_ini(Tail, Group, Res); | |
$[ -> parse_ini(Tail, string:strip(R, both, $]), Res); | |
_ -> [K|V] = string:tokens(Str, "="), | |
parse_ini(Tail, Group, [{{Group, K}, string:join(V,"=")}|Res]) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment