From f2d16b7fc3c5f1bd8e6ff91d933049dc6947ad56 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 22 Jun 2023 09:32:04 -0500 Subject: [PATCH] changed: minor things in ini parser --- core/encoding/ini.onyx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/encoding/ini.onyx b/core/encoding/ini.onyx index 1fe9e8c1..fde2e317 100644 --- a/core/encoding/ini.onyx +++ b/core/encoding/ini.onyx @@ -153,7 +153,7 @@ parse_ini_file_inner :: (r: &io.Reader, output_ptr: any) -> (IniParseResult, Ini |> string.alloc_copy(); } else { - error(aprintf("Failed to parse value.")); + error(aprintf("Failed to parse value of type '{}' from string '{}'.", field.type, value_string)); } } @@ -167,15 +167,15 @@ parse_ini_file_inner :: (r: &io.Reader, output_ptr: any) -> (IniParseResult, Ini // // Outputs a two-level structure into an ini file. The inverse of `parse_ini_file`. -write_ini_file :: macro (w: &io.Writer, output: $T/type_is_struct) => { +write_ini_file :: macro (w: &io.Writer, output: $T/type_is_struct, leave_empty_strings := false) => { write_ini_file_inner :: write_ini_file_inner // See note above in parse_ini_file. - return write_ini_file_inner(w, output); + return write_ini_file_inner(w, output, leave_empty_strings); } #local -write_ini_file_inner :: (w: &io.Writer, output: any) -> bool { +write_ini_file_inner :: (w: &io.Writer, output: any, leave_empty_strings := false) -> bool { info :: runtime.info output_info := cast(&info.Type_Info_Struct) info.get_type_info(output.type); @@ -200,6 +200,12 @@ write_ini_file_inner :: (w: &io.Writer, output: any) -> bool { } for& prop: member_info.members { + if !leave_empty_strings && prop.type == str { + if cast(&str, member_data + prop.offset).length == 0 { + continue; + } + } + io.write_format_va(w, "{}={}\n", .[ .{&prop.name, str}, .{member_data + prop.offset, prop.type} -- 2.25.1