Skip to content

Instantly share code, notes, and snippets.

@endo64
Created January 13, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endo64/e1c0f0db9b287e2e1392604f79d9f3fd to your computer and use it in GitHub Desktop.
Save endo64/e1c0f0db9b287e2e1392604f79d9f3fd to your computer and use it in GitHub Desktop.
Red [
title: "Loads an INI file and returns a map!"
notes: "semi-colons treats as comment"
]
load-ini: function [ini [file! string!]] [
m: copy #()
if file? ini [ini: read ini]
parse ini [some [copy word to "=" skip copy value to [";" | newline | end] pos: (
if #";" = pos/1 [
unless pos: find pos newline [pos: tail ini]
]
put m load word trim value
) :pos skip]]
m
]
write %file.ini rejoin ["a=1" newline " bc = value with space" newline " d = value; and comment " newline "ef=last"]
probe load-ini %file.ini
comment [
>> write %file.ini rejoin ["a=1" newline " bc = 3" newline " d = test; comment " newline "ef=end"]
>> probe load-ini %file.ini
== #(
a: "1"
bc: "3"
d: "test"
ef: "end"
)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment