@@ -98,10 +98,18 @@ module json_module
98
98
integer ,parameter ,public :: wp = selected_real_kind (15 ,307 ) ! double precision reals
99
99
character (len=* ),parameter ,public :: json_ext = ' .json' ! JSON file extension
100
100
101
- character (len= 1 ),parameter :: space = ' '
102
- character (len= 1 ),parameter :: newline = ACHAR (10 ) ! new line character
103
- character (len=* ),parameter :: real_fmt = ' (E30.16E3)' ! format for real numbers
104
- character (len=* ),parameter :: int_fmt = ' (I10)' ! format for integers
101
+ character (len= 1 ),parameter :: space = ' ' ! special characters
102
+ character (len= 1 ),parameter :: bspace = achar (8 )
103
+ character (len= 1 ),parameter :: horizontal_tab = achar (9 )
104
+ character (len= 1 ),parameter :: newline = achar (10 )
105
+ character (len= 1 ),parameter :: formfeed = achar (12 )
106
+ character (len= 1 ),parameter :: carriage_return = achar (13 )
107
+ character (len= 1 ),parameter :: quotation_mark = achar (34 )
108
+ character (len= 1 ),parameter :: slash = achar (47 )
109
+ character (len= 1 ),parameter :: backslash = achar (92 )
110
+
111
+ character (len=* ),parameter :: real_fmt = ' (E30.16E3)' ! format for real numbers
112
+ character (len=* ),parameter :: int_fmt = ' (I10)' ! format for integers
105
113
106
114
logical ,parameter :: debug = .false. ! for printing the debug messages
107
115
@@ -1442,19 +1450,20 @@ subroutine escape_string(str_in, str_out)
1442
1450
1443
1451
select case (c)
1444
1452
1445
- case (' "' ,ACHAR (92 ),' /' ,ACHAR (8 ),ACHAR (12 ),ACHAR (10 ),ACHAR (13 ),ACHAR (9 )) ! special characters
1453
+ case (quotation_mark,backslash,slash,bspace,&
1454
+ formfeed,newline,carriage_return,horizontal_tab) ! special characters
1446
1455
select case (c)
1447
- case (' " ' , ACHAR ( 92 ), ' / ' )
1448
- str_out = str_out// ACHAR ( 92 ) // c ! add escape char
1449
- case (ACHAR ( 8 ) )
1456
+ case (quotation_mark,backslash,slash )
1457
+ str_out = str_out// backslash // c ! add escape char
1458
+ case (bspace )
1450
1459
str_out = str_out// ' \b' ! backspace
1451
- case (ACHAR ( 12 ) )
1460
+ case (formfeed )
1452
1461
str_out = str_out// ' \f' ! formfeed
1453
- case (ACHAR ( 10 ) )
1462
+ case (newline )
1454
1463
str_out = str_out// ' \n' ! new line
1455
- case (ACHAR ( 13 ) )
1464
+ case (carriage_return )
1456
1465
str_out = str_out// ' \r' ! carriage return
1457
- case (ACHAR ( 9 ) )
1466
+ case (horizontal_tab )
1458
1467
str_out = str_out// ' \t' ! horizontal tab
1459
1468
end select
1460
1469
case default
@@ -2208,7 +2217,7 @@ subroutine json_get_integer(this, path, value, found)
2208
2217
case (json_integer)
2209
2218
value = p% data % int_value
2210
2219
case (json_real)
2211
- value = p% data % dbl_value
2220
+ value = int ( p% data % dbl_value)
2212
2221
case (json_logical)
2213
2222
if (p% data % log_value) then
2214
2223
value = 1
@@ -2631,7 +2640,7 @@ subroutine json_get_chars(this, path, value, found)
2631
2640
do
2632
2641
2633
2642
jprev = j ! initialize
2634
- j = index (s(j:n),ACHAR ( 92 ) ) ! look for an escape character
2643
+ j = index (s(j:n),backslash ) ! look for an escape character
2635
2644
2636
2645
if (j> 0 ) then ! an escape character was found
2637
2646
@@ -2650,7 +2659,7 @@ subroutine json_get_chars(this, path, value, found)
2650
2659
c = s( j+1 : j+1 )
2651
2660
2652
2661
select case (c)
2653
- case (' " ' , ACHAR ( 92 ), ' / ' ,' b' ,' f' ,' n' ,' r' ,' t' )
2662
+ case (quotation_mark,backslash,slash ,' b' ,' f' ,' n' ,' r' ,' t' )
2654
2663
2655
2664
! save the bit after the escape characters:
2656
2665
if (j+2 < n) then
@@ -2660,18 +2669,18 @@ subroutine json_get_chars(this, path, value, found)
2660
2669
end if
2661
2670
2662
2671
select case (c)
2663
- case (' " ' , ACHAR ( 92 ), ' / ' )
2672
+ case (quotation_mark,backslash,slash )
2664
2673
! use c as is
2665
2674
case (' b' )
2666
- c = ACHAR ( 8 ) ! backspace
2675
+ c = bspace
2667
2676
case (' f' )
2668
- c = ACHAR ( 12 ) ! formfeed
2677
+ c = formfeed
2669
2678
case (' n' )
2670
- c = ACHAR ( 10 ) ! new line
2679
+ c = newline
2671
2680
case (' r' )
2672
- c = ACHAR ( 13 ) ! carriage return
2681
+ c = carriage_return
2673
2682
case (' t' )
2674
- c = ACHAR ( 9 ) ! horizontal tab
2683
+ c = horizontal_tab
2675
2684
end select
2676
2685
2677
2686
s = pre// c// post
@@ -2694,7 +2703,7 @@ subroutine json_get_chars(this, path, value, found)
2694
2703
case default
2695
2704
! unknown escape character
2696
2705
call throw_exception(' Error in json_get_chars: unknown escape sequence in string "' // &
2697
- trim (s)// ' " [' // ACHAR ( 92 ) // c// ' ]' )
2706
+ trim (s)// ' " [' // backslash // c// ' ]' )
2698
2707
exit
2699
2708
end select
2700
2709
@@ -3626,7 +3635,7 @@ subroutine parse_string(unit, string)
3626
3635
call throw_exception(' Error in parse_string: Expecting end of string' )
3627
3636
return
3628
3637
3629
- else if (' "' == c .and. last /= ACHAR ( 92 ) ) then
3638
+ else if (' "' == c .and. last /= backslash ) then
3630
3639
3631
3640
if (is_hex) call throw_exception(' Error in parse_string: incomplete hex string: \u' // trim (hex))
3632
3641
exit
@@ -3660,7 +3669,7 @@ subroutine parse_string(unit, string)
3660
3669
escape = .false.
3661
3670
is_hex = (c==' u' ) ! the next four characters are the hex string
3662
3671
else
3663
- escape = (c== ACHAR ( 92 ) )
3672
+ escape = (c== backslash )
3664
3673
end if
3665
3674
3666
3675
end if
0 commit comments