@@ -216,11 +216,12 @@ module json_value_module
216
216
! ! then the string is returned unescaped.
217
217
218
218
logical (LK) :: allow_comments = .true. ! ! if true, any comments will be ignored when
219
- ! ! parsing a file. The comment token is defined
219
+ ! ! parsing a file. The comment tokens are defined
220
220
! ! by the `comment_char` character variable.
221
- character (kind= CK,len= 1 ) :: comment_char = CK_' !' ! ! comment token when
222
- ! ! `allow_comments` is true.
223
- ! ! Examples: '`!`' or '`#`'.
221
+ character (kind= CK,len= :),allocatable :: comment_char ! ! comment tokens when
222
+ ! ! `allow_comments` is true.
223
+ ! ! Examples: '`!`' or '`#`'.
224
+ ! ! Default is `CK_'/!#'`.
224
225
225
226
integer (IK) :: path_mode = 1_IK ! ! How the path strings are interpreted in the
226
227
! ! `get_by_path` routines:
@@ -1081,7 +1082,7 @@ subroutine json_initialize(me,&
1081
1082
! [an empty string disables comments]
1082
1083
if (present (comment_char)) then
1083
1084
me% allow_comments = comment_char/= CK_' '
1084
- me% comment_char = comment_char
1085
+ me% comment_char = trim ( adjustl ( comment_char))
1085
1086
end if
1086
1087
1087
1088
! path separator:
@@ -9736,6 +9737,12 @@ subroutine json_parse_file(json, file, p, unit)
9736
9737
! clear any exceptions and initialize:
9737
9738
call json% initialize()
9738
9739
9740
+ if (json% allow_comments .and. .not. allocated (json% comment_char)) then
9741
+ ! comments are enabled, but user hasn't set the comment char,
9742
+ ! so in this case use the default:
9743
+ json% comment_char = CK_' /!#'
9744
+ end if
9745
+
9739
9746
if ( present (unit) ) then
9740
9747
9741
9748
if (unit== 0 ) then
@@ -9846,6 +9853,12 @@ subroutine json_parse_string(json, p, str)
9846
9853
! clear any exceptions and initialize:
9847
9854
call json% initialize()
9848
9855
9856
+ if (json% allow_comments .and. .not. allocated (json% comment_char)) then
9857
+ ! comments are enabled, but user hasn't set the comment char,
9858
+ ! so in this case use the default:
9859
+ json% comment_char = CK_' /!#'
9860
+ end if
9861
+
9849
9862
! create the value and associate the pointer
9850
9863
call json_value_create(p)
9851
9864
@@ -11435,7 +11448,7 @@ subroutine pop_char(json,unit,str,skip_ws,skip_comments,eof,popped)
11435
11448
11436
11449
end if
11437
11450
11438
- if (ignore_comments .and. (parsing_comment .or. c == json% comment_char) ) then
11451
+ if (ignore_comments .and. (parsing_comment .or. scan (c, json% comment_char,kind = IK)> 0_IK ) ) then
11439
11452
11440
11453
! skipping the comment
11441
11454
parsing_comment = .true.
0 commit comments