From fa89439994bb5042851b70df7161404be374aae6 Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Mon, 29 Jan 2024 01:03:13 +0100 Subject: [PATCH] src/ini_parser.f90: handle inline comments and whitespace While the Fortran read statement will ignore whitespace and ignored remaining tokens, these are problematic when manually parsing the INI values. --- src/ini_parser.f90 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ini_parser.f90 b/src/ini_parser.f90 index 81bf8db..886c3e4 100644 --- a/src/ini_parser.f90 +++ b/src/ini_parser.f90 @@ -112,6 +112,10 @@ contains cycle end if + ! remove possible inline comments + sep = index(line, comment_sign, back=.true.) + if (sep /= 0) line = line(1:sep-1) + ! split line at separator (ex. name=value) sep = index(line, property_sep) if (sep == 0) then @@ -120,8 +124,12 @@ contains error = ERR_SYNTAX exit end if - name = trim(line(1:sep - 1)) - value = trim(line(sep + 1:)) + name = line(1:sep - 1) + value = line(sep + 1:) + + ! remove leading/trailing whitespace + name = trim(adjustl(name)) + value = trim(adjustl(value)) ! call the handler select case (handler(section, name, value))