Skip to content

Commit

Permalink
added more true/false options
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Oct 27, 2023
1 parent c649f37 commit 3372b09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/fortran_yaml_c_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion tests/example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test1.yaml
Original file line number Diff line number Diff line change
@@ -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": {}
Expand Down

0 comments on commit 3372b09

Please sign in to comment.