From 7d2ee68acfd265ff882a5db7f443cbda5047b94c Mon Sep 17 00:00:00 2001 From: Jacob Williams Date: Thu, 18 Jul 2019 22:06:17 -0500 Subject: [PATCH 1/2] Allow the parser to work with some nonstandard real value representations (leading +, no leading digit before decimal, D/d format). Fixes #417 --- src/json_value_module.F90 | 8 ++++---- src/tests/jf_test_42.F90 | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/json_value_module.F90 b/src/json_value_module.F90 index 9c87818fbe..31412151f8 100644 --- a/src/json_value_module.F90 +++ b/src/json_value_module.F90 @@ -10110,7 +10110,7 @@ recursive subroutine parse_value(json, unit, str, value) call json%parse_for_chars(unit, str, null_str(2:)) if (.not. json%exception_thrown) call json%to_null(value) ! allocate class - case(CK_'-', CK_'0': CK_'9') + case(CK_'-', CK_'0': CK_'9', CK_'.', CK_'+') call json%push_char(c) call json%parse_number(unit, str, value) @@ -10118,8 +10118,8 @@ recursive subroutine parse_value(json, unit, str, value) case default call json%throw_exception('Error in parse_value:'//& - ' Unexpected character while parsing value. "'//& - c//'"') + ' Unexpected character while parsing value. "'//& + c//'"') end select end if @@ -11132,7 +11132,7 @@ subroutine parse_number(json, unit, str, value) tmp(ip:ip) = c ip = ip + 1 - case(CK_'.',CK_'E',CK_'e') !can be present in real numbers + case(CK_'.',CK_'E',CK_'e',CK_'D',CK_'d') !can be present in real numbers if (is_integer) is_integer = .false. diff --git a/src/tests/jf_test_42.F90 b/src/tests/jf_test_42.F90 index cca7301d4a..68a7755382 100644 --- a/src/tests/jf_test_42.F90 +++ b/src/tests/jf_test_42.F90 @@ -23,7 +23,10 @@ subroutine test_42(error_cnt) type(json_file) :: json !! the JSON structure read from the file integer,intent(out) :: error_cnt !! error counter - character(kind=CK,len=*),parameter :: str = CK_'{"bad_reals": [1.0, null, "NaN", "+Infinity", "-Infinity", 4.0]}' + character(kind=CK,len=*),parameter :: str = CK_'{'//& + '"bad_reals": [1.0, null, "NaN", "+Infinity", "-Infinity", 4.0],'//& + '"nonstandard_json": [.1e1, .1D1, .1d+1, +.1d1, +.1D1, +1.0, +1.0d0, +1.0D0]'//& + '}' real(rk),dimension(:),allocatable :: bad_reals logical(lk) :: found From 06512134bf0ab741d03c4e03c1ce81ff1f819188 Mon Sep 17 00:00:00 2001 From: Jacob Williams Date: Thu, 18 Jul 2019 22:13:54 -0500 Subject: [PATCH 2/2] fixed str cat issue with unicode --- src/tests/jf_test_42.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/jf_test_42.F90 b/src/tests/jf_test_42.F90 index 68a7755382..eba6de25dc 100644 --- a/src/tests/jf_test_42.F90 +++ b/src/tests/jf_test_42.F90 @@ -24,9 +24,9 @@ subroutine test_42(error_cnt) integer,intent(out) :: error_cnt !! error counter character(kind=CK,len=*),parameter :: str = CK_'{'//& - '"bad_reals": [1.0, null, "NaN", "+Infinity", "-Infinity", 4.0],'//& - '"nonstandard_json": [.1e1, .1D1, .1d+1, +.1d1, +.1D1, +1.0, +1.0d0, +1.0D0]'//& - '}' + CK_'"bad_reals": [1.0, null, "NaN", "+Infinity", "-Infinity", 4.0],'//& + CK_'"nonstandard_json": [.1e1, .1D1, .1d+1, +.1d1, +.1D1, +1.0, +1.0d0, +1.0D0]'//& + CK_'}' real(rk),dimension(:),allocatable :: bad_reals logical(lk) :: found