misc

Misc scripts and tools
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 4ec4536708ffb373e502e4424e9450af2cec46f4
parent 503671a902d555ff837df1d1d51488a52535b624
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 17 Oct 2021 21:12:35 -0700

ini parser

Diffstat:
Aini.rs | 32++++++++++++++++++++++++++++++++
Atest.ini | 2++
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/ini.rs b/ini.rs @@ -0,0 +1,32 @@ +use std::fs::File; +use std::io::{self, BufRead}; +use std::path::Path; + +// Parse very simple configuration files of the form key=value + +fn main() -> std::io::Result<()> { + let filename = "test.ini"; + let file = File::open(filename)?; + for l in io::BufReader::new(file).lines() { + let line = l?; + if line.len() == 0 { + continue; + } + if let Some(i) = line.find('=') { + let key = &line[..i]; + let value = &line[i + 1..]; + match key { + "foo" => { + let foo = value; + println!("{}", foo); + } + _ => {} + } + // Debug line + } else { + // Replace with whatever you want to do on malformed config lines + panic!("Invalid config") + } + } + Ok(()) +} diff --git a/test.ini b/test.ini @@ -0,0 +1,2 @@ +foo=bar +hello=world