From 3372b098ba6fc79f680293aa6b4b67e3930c4204 Mon Sep 17 00:00:00 2001 From: Nick Wogan Date: Fri, 27 Oct 2023 08:52:10 -0700 Subject: [PATCH] added more true/false options --- src/fortran_yaml_c_types.f90 | 10 ++++++++-- tests/example.f90 | 9 ++++++++- tests/test1.yaml | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/fortran_yaml_c_types.f90 b/src/fortran_yaml_c_types.f90 index e786c91..39a3adf 100644 --- a/src/fortran_yaml_c_types.f90 +++ b/src/fortran_yaml_c_types.f90 @@ -277,8 +277,14 @@ function scalar_to_logical(self, default, success) result(value) logical, optional, intent(out) :: success logical :: value - character(len=20), parameter :: true_strings(3) = ["true","True",'TRUE'] - character(len=20), parameter :: false_strings(3) = ["false","False",'FALSE'] + character(len=20), parameter :: true_strings(*) = & + ['true','True','TRUE', & + 'on ','On ','ON ', & + 'y ','Y ','yes ','Yes ','YES '] + character(len=20), parameter :: false_strings(*) = & + ["false","False",'FALSE', & + 'off ','Off ','OFF ', & + 'n ','N ','no ','No ','NO '] value = default diff --git a/tests/example.f90 b/tests/example.f90 index 12163f4..2705712 100644 --- a/tests/example.f90 +++ b/tests/example.f90 @@ -19,7 +19,7 @@ subroutine main() character(:), allocatable :: string real(dp) :: pi - logical :: happy + logical :: happy, sadness call file%parse("../tests/test1.yaml", err) if (allocated(err)) then @@ -47,6 +47,13 @@ subroutine main() stop 1 endif print*,"happy: ",happy + + sadness = root%get_logical('sadness',error=io_err) + if (allocated(io_err)) then + print*,io_err%message + stop 1 + endif + print*,"sadness: ",sadness dict => root%get_dictionary('reaction',required=.true.,error=io_err) if (allocated(io_err)) then diff --git a/tests/test1.yaml b/tests/test1.yaml index 11f3c55..463adfe 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -1,5 +1,6 @@ pi: 3.14159 happy-today: true +sadness: off groceries: [eggs, butter, oil, bread] list-that-is-empty: [] "dictionary that-is-empty": {}