@@ -8752,11 +8752,11 @@ subroutine json_parse_file(json, file, p, unit)
8752
8752
! but we'll allocate something here just in case.
8753
8753
p% name = trim (file) ! use the file name
8754
8754
8755
- ! parse as a value
8755
+ ! parse as a value
8756
8756
call json% parse_value(unit= iunit, str= CK_' ' , value= p)
8757
8757
8758
- ! close the file if necessary
8759
- close (unit= iunit, iostat= istat)
8758
+ ! close the file if necessary
8759
+ close (unit= iunit, iostat= istat)
8760
8760
8761
8761
! check for errors:
8762
8762
if (json% exception_thrown) then
@@ -9868,22 +9868,22 @@ end subroutine parse_array
9868
9868
! * Jacob Williams : 6/16/2014 : Added hex validation.
9869
9869
! * Jacob Williams : 12/3/2015 : Fixed some bugs.
9870
9870
! * Jacob Williams : 8/23/2015 : `string` is now returned unescaped.
9871
+ ! * Jacob Williams : 7/21/2018 : moved hex validate to [[unescape_string]].
9871
9872
9872
9873
subroutine parse_string (json , unit , str , string )
9873
9874
9874
9875
implicit none
9875
9876
9876
9877
class(json_core),intent (inout ) :: json
9877
- integer (IK),intent (in ) :: unit ! ! file unit number (if parsing from a file)
9878
- character (kind= CK,len=* ),intent (in ) :: str ! ! JSON string (if parsing from a string)
9879
- character (kind= CK,len= :),allocatable ,intent (out ) :: string ! ! the string (unescaped if necessary)
9878
+ integer (IK),intent (in ) :: unit ! ! file unit number (if
9879
+ ! ! parsing from a file)
9880
+ character (kind= CK,len=* ),intent (in ) :: str ! ! JSON string (if parsing
9881
+ ! ! from a string)
9882
+ character (kind= CK,len= :),allocatable ,intent (out ) :: string ! ! the string (unescaped
9883
+ ! ! if necessary)
9880
9884
9881
9885
logical (LK) :: eof ! ! end of file flag
9882
- logical (LK) :: is_hex ! ! it is a hex string
9883
- logical (LK) :: escape ! ! for escape string parsing
9884
9886
character (kind= CK,len= 1 ) :: c ! ! character returned by [[pop_char]]
9885
- character (kind= CK,len= 4 ) :: hex ! ! hex string
9886
- integer (IK) :: i ! ! counter
9887
9887
integer (IK) :: ip ! ! index to put next character,
9888
9888
! ! to speed up by reducing the number
9889
9889
! ! of character string reallocations.
@@ -9895,10 +9895,7 @@ subroutine parse_string(json, unit, str, string)
9895
9895
if (.not. json% exception_thrown) then
9896
9896
9897
9897
! initialize:
9898
- ip = 1
9899
- is_hex = .false.
9900
- escape = .false.
9901
- i = 0
9898
+ ip = 1
9902
9899
9903
9900
do
9904
9901
@@ -9910,10 +9907,8 @@ subroutine parse_string(json, unit, str, string)
9910
9907
call json% throw_exception(' Error in parse_string: Expecting end of string' )
9911
9908
return
9912
9909
9913
- else if (c== quotation_mark .and. .not. escape ) then ! end of string
9910
+ else if (c== quotation_mark) then ! end of string
9914
9911
9915
- if (is_hex) call json% throw_exception(' Error in parse_string:' // &
9916
- ' incomplete hex string: \u' // trim (hex))
9917
9912
exit
9918
9913
9919
9914
else
@@ -9925,36 +9920,6 @@ subroutine parse_string(json, unit, str, string)
9925
9920
string (ip:ip) = c
9926
9921
ip = ip + 1
9927
9922
9928
- ! hex validation:
9929
- if (is_hex) then ! accumulate the four characters after '\u'
9930
-
9931
- i= i+1
9932
- hex(i:i) = c
9933
- if (i== 4 ) then
9934
- if (valid_json_hex(hex)) then
9935
- i = 0
9936
- hex = CK_' '
9937
- is_hex = .false.
9938
- else
9939
- call json% throw_exception(' Error in parse_string:' // &
9940
- ' invalid hex string: \u' // trim (hex))
9941
- exit
9942
- end if
9943
- end if
9944
-
9945
- else
9946
-
9947
- ! when the '\u' string is encountered, then
9948
- ! start accumulating the hex string (should be the next 4 characters)
9949
- if (escape) then
9950
- escape = .false.
9951
- is_hex = (c== CK_' u' ) ! the next four characters are the hex string
9952
- else
9953
- escape = (c== backslash)
9954
- end if
9955
-
9956
- end if
9957
-
9958
9923
end if
9959
9924
9960
9925
end do
@@ -9968,7 +9933,8 @@ subroutine parse_string(json, unit, str, string)
9968
9933
end if
9969
9934
end if
9970
9935
9971
- ! string is returned unescaped:
9936
+ ! string is returned unescaped:
9937
+ ! (this will also validate any hex strings present)
9972
9938
call unescape_string(string,error_message)
9973
9939
if (allocated (error_message)) then
9974
9940
call json% throw_exception(error_message)
0 commit comments