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.
This commit is contained in:
Michele Guerini Rocco 2024-01-29 01:03:13 +01:00
parent 73bd010458
commit fa89439994
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450

View File

@ -112,6 +112,10 @@ contains
cycle cycle
end if 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<here>=value) ! split line at separator (ex. name<here>=value)
sep = index(line, property_sep) sep = index(line, property_sep)
if (sep == 0) then if (sep == 0) then
@ -120,8 +124,12 @@ contains
error = ERR_SYNTAX error = ERR_SYNTAX
exit exit
end if end if
name = trim(line(1:sep - 1)) name = line(1:sep - 1)
value = trim(line(sep + 1:)) value = line(sep + 1:)
! remove leading/trailing whitespace
name = trim(adjustl(name))
value = trim(adjustl(value))
! call the handler ! call the handler
select case (handler(section, name, value)) select case (handler(section, name, value))