@@ -500,9 +500,6 @@ module json_module
500500 MAYBEWRAP(json_file_get_logical_vec), &
501501 MAYBEWRAP(json_file_get_string_vec)
502502
503-
504-
505-
506503 generic,public :: update = > MAYBEWRAP(json_file_update_integer), &
507504 MAYBEWRAP(json_file_update_logical), &
508505 MAYBEWRAP(json_file_update_real), &
@@ -1437,7 +1434,7 @@ subroutine json_file_print_2(me,filename)
14371434
14381435 implicit none
14391436
1440- class(json_file),intent (inout ) :: me
1437+ class(json_file),intent (inout ) :: me
14411438 character (kind= CDK,len=* ),intent (in ) :: filename
14421439
14431440 integer (IK) :: iunit,istat
@@ -6351,32 +6348,39 @@ subroutine annotate_invalid_json(iunit,str)
63516348
63526349 ! draw the arrow string that points to the current character:
63536350 arrow_str = repeat (' -' ,max ( 0 , char_count - 1 ) )// ' ^'
6351+
6352+ if (line_count> 0 .and. char_count> 0 ) then
63546353
6355- if (iunit/= 0 ) then
6354+ if (iunit/= 0 ) then
6355+
6356+ if (use_unformatted_stream) then
6357+ call get_current_line_from_file_stream(iunit,line)
6358+ else
6359+ call get_current_line_from_file_sequential(iunit,line)
6360+ end if
63566361
6357- if (use_unformatted_stream) then
6358- call get_current_line_from_file_stream(iunit,line)
63596362 else
6360- call get_current_line_from_file_sequential(iunit,line)
6361- end if
63626363
6363- else
6364+ ! get the current line from the string:
6365+ ! [this is done by counting the newline characters]
6366+ i_nl_prev = 0 ! index of previous newline character
6367+ i_nl = 2 ! just in case line_count = 0
6368+ do i= 1 ,line_count
6369+ i_nl = index (str(i_nl_prev+1 :),newline)
6370+ if (i_nl== 0 ) then ! last line - no newline character
6371+ i_nl = len (str)+ 1
6372+ exit
6373+ end if
6374+ i_nl = i_nl + i_nl_prev ! index of current newline character
6375+ i_nl_prev = i_nl ! update for next iteration
6376+ end do
6377+ line = str(i_nl_prev+1 : i_nl-1 ) ! extract current line
63646378
6365- ! get the current line from the string:
6366- ! [this is done by counting the newline characters]
6367- i_nl_prev = 0 ! index of previous newline character
6368- i_nl = 2 ! just in case line_count = 0
6369- do i= 1 ,line_count
6370- i_nl = index (str(i_nl_prev+1 :),newline)
6371- if (i_nl== 0 ) then ! last line - no newline character
6372- i_nl = len (str)+ 1
6373- exit
6374- end if
6375- i_nl = i_nl + i_nl_prev ! index of current newline character
6376- i_nl_prev = i_nl ! update for next iteration
6377- end do
6378- line = str(i_nl_prev+1 : i_nl-1 ) ! extract current line
6379+ end if
63796380
6381+ else
6382+ ! in this case, it was an empty line or file
6383+ line = ' '
63806384 end if
63816385
63826386 ! create the error message:
@@ -6469,9 +6473,7 @@ subroutine get_current_line_from_file_stream(iunit,line)
64696473 integer (IK) :: istart,iend,ios
64706474 character (kind= CK,len= 1 ) :: c
64716475
6472- ! ....update for the new STREAM version.....
6473-
6474- ! !!! !!!! not quite right for EXAMPLE 6 case 2 ..... DOUBLE CHECK THIS...
6476+ ! updated for the new STREAM version:
64756477
64766478 istart = ipos
64776479 do
0 commit comments