Skip to content

Commit b0c7a28

Browse files
committed
Merge pull request #20 from zbeekman/char-vs-achar-bug
BUGFIX: char() is processor dependent, use achar()
2 parents b812e28 + a677e7b commit b0c7a28

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/json_module.f90

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ module json_module
9999
character(len=*),parameter,public :: json_ext = '.json' !JSON file extension
100100

101101
character(len=1),parameter :: space = ' '
102-
character(len=1),parameter :: newline = char(10) !new line character
102+
character(len=1),parameter :: newline = ACHAR(10) !new line character
103103
character(len=*),parameter :: real_fmt = '(E30.16E3)' !format for real numbers
104-
character(len=*),parameter :: int_fmt = '(I10)' !format for integers
104+
character(len=*),parameter :: int_fmt = '(I10)' !format for integers
105105

106106
logical,parameter :: debug = .false. !for printing the debug messages
107107

@@ -1442,19 +1442,19 @@ subroutine escape_string(str_in, str_out)
14421442

14431443
select case(c)
14441444

1445-
case('"','\','/',CHAR(8),CHAR(12),CHAR(10),CHAR(13),CHAR(9)) !special characters
1445+
case('"',ACHAR(92),'/',ACHAR(8),ACHAR(12),ACHAR(10),ACHAR(13),ACHAR(9)) !special characters
14461446
select case(c)
1447-
case('"','\','/')
1448-
str_out = str_out//'\'//c !add escape char
1449-
case(CHAR(8))
1447+
case('"',ACHAR(92),'/')
1448+
str_out = str_out//ACHAR(92)//c !add escape char
1449+
case(ACHAR(8))
14501450
str_out = str_out//'\b' !backspace
1451-
case(CHAR(12))
1451+
case(ACHAR(12))
14521452
str_out = str_out//'\f' !formfeed
1453-
case(CHAR(10))
1453+
case(ACHAR(10))
14541454
str_out = str_out//'\n' !new line
1455-
case(CHAR(13))
1455+
case(ACHAR(13))
14561456
str_out = str_out//'\r' !carriage return
1457-
case(CHAR(9))
1457+
case(ACHAR(9))
14581458
str_out = str_out//'\t' !horizontal tab
14591459
end select
14601460
case default
@@ -2631,7 +2631,7 @@ subroutine json_get_chars(this, path, value, found)
26312631
do
26322632

26332633
jprev = j !initialize
2634-
j = index(s(j:n),'\') !look for an escape character
2634+
j = index(s(j:n),ACHAR(92)) !look for an escape character
26352635

26362636
if (j>0) then !an escape character was found
26372637

@@ -2650,7 +2650,7 @@ subroutine json_get_chars(this, path, value, found)
26502650
c = s( j+1 : j+1 )
26512651

26522652
select case (c)
2653-
case('"','\','/','b','f','n','r','t')
2653+
case('"',ACHAR(92),'/','b','f','n','r','t')
26542654

26552655
!save the bit after the escape characters:
26562656
if (j+2<n) then
@@ -2660,18 +2660,18 @@ subroutine json_get_chars(this, path, value, found)
26602660
end if
26612661

26622662
select case(c)
2663-
case('"','\','/')
2663+
case('"',ACHAR(92),'/')
26642664
!use c as is
26652665
case('b')
2666-
c = CHAR(8) !backspace
2666+
c = ACHAR(8) !backspace
26672667
case('f')
2668-
c = CHAR(12) !formfeed
2668+
c = ACHAR(12) !formfeed
26692669
case('n')
2670-
c = CHAR(10) !new line
2670+
c = ACHAR(10) !new line
26712671
case('r')
2672-
c = CHAR(13) !carriage return
2672+
c = ACHAR(13) !carriage return
26732673
case('t')
2674-
c = CHAR(9) !horizontal tab
2674+
c = ACHAR(9) !horizontal tab
26752675
end select
26762676

26772677
s = pre//c//post
@@ -2694,7 +2694,7 @@ subroutine json_get_chars(this, path, value, found)
26942694
case default
26952695
!unknown escape character
26962696
call throw_exception('Error in json_get_chars: unknown escape sequence in string "'//&
2697-
trim(s)//'" [\'//c//']')
2697+
trim(s)//'" ['//ACHAR(92)//c//']')
26982698
exit
26992699
end select
27002700

@@ -3626,7 +3626,7 @@ subroutine parse_string(unit, string)
36263626
call throw_exception('Error in parse_string: Expecting end of string')
36273627
return
36283628

3629-
else if ('"' == c .and. last /= '\') then
3629+
else if ('"' == c .and. last /= ACHAR(92)) then
36303630

36313631
if (is_hex) call throw_exception('Error in parse_string: incomplete hex string: \u'//trim(hex))
36323632
exit
@@ -3660,7 +3660,7 @@ subroutine parse_string(unit, string)
36603660
escape = .false.
36613661
is_hex = (c=='u') !the next four characters are the hex string
36623662
else
3663-
escape = (c=='\')
3663+
escape = (c==ACHAR(92))
36643664
end if
36653665

36663666
end if

0 commit comments

Comments
 (0)