Skip to content

Commit 82e2c03

Browse files
committed
First cut at adding RFC 6901 support.
1 parent 74b5c2b commit 82e2c03

File tree

5 files changed

+525
-171
lines changed

5 files changed

+525
-171
lines changed

src/json_file_module.F90

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module json_file_module
3030
! The `json_file` is the main public class that is
3131
! used to open a file and get data from it.
3232
!
33-
! A `json_file` contains only two items: an instance of a [[json_core]],
33+
! A `json_file` contains only two items: an instance of a [[json_core(type)]],
3434
! which use used for all data manipulation, and a [[json_value]],
3535
! which is used to construct the linked-list data structure.
3636
! Note that most methods in the `json_file` class are simply wrappers
@@ -61,7 +61,7 @@ module json_file_module
6161

6262
private
6363

64-
type(json_core) :: core !! The instance of the [[json_core]] factory used for this file.
64+
type(json_core) :: core !! The instance of the [[json_core(type)]] factory used for this file.
6565
type(json_value),pointer :: p => null() !! the JSON structure read from the file
6666

6767
contains
@@ -165,8 +165,8 @@ module json_file_module
165165
! date: 07/23/2015
166166
!
167167
! Structure constructor to initialize a [[json_file(type)]] object
168-
! with an existing [[json_value]] object, and either the [[json_core]]
169-
! settings or a [[json_core]] instance.
168+
! with an existing [[json_value]] object, and either the [[json_core(type)]]
169+
! settings or a [[json_core(type)]] instance.
170170
!
171171
!# Example
172172
!
@@ -258,7 +258,7 @@ end subroutine json_file_print_error_message
258258

259259
!*****************************************************************************************
260260
!>
261-
! Initialize the [[json_core]] for this [[json_file]].
261+
! Initialize the [[json_core(type)]] for this [[json_file]].
262262
! This is just a wrapper for [[json_initialize]].
263263
!
264264
!@note: This does not destroy the data in the file.
@@ -274,35 +274,13 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
274274
case_sensitive_keys,&
275275
no_whitespace,&
276276
unescape_strings,&
277-
comment_char)
277+
comment_char,&
278+
use_rfc6901_paths)
278279

279280
implicit none
280281

281282
class(json_file),intent(inout) :: me
282-
logical(LK),intent(in),optional :: verbose !! mainly useful for debugging (default is false)
283-
logical(LK),intent(in),optional :: compact_reals !! to compact the real number strings for output (default is true)
284-
logical(LK),intent(in),optional :: print_signs !! always print numeric sign (default is false)
285-
character(kind=CDK,len=*),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
286-
integer(IK),intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
287-
logical(LK),intent(in),optional :: strict_type_checking !! if true, no integer, double, or logical type
288-
!! conversions are done for the `get` routines
289-
!! (default is false)
290-
logical(LK),intent(in),optional :: trailing_spaces_significant !! for name and path comparisons, is trailing
291-
!! space to be considered significant.
292-
!! (default is false)
293-
logical(LK),intent(in),optional :: case_sensitive_keys !! for name and path comparisons, are they
294-
!! case sensitive. (default is true)
295-
logical(LK),intent(in),optional :: no_whitespace !! if true, printing the JSON structure is
296-
!! done without adding any non-significant
297-
!! spaces or linebreaks (default is false)
298-
logical(LK),intent(in),optional :: unescape_strings !! If false, then the raw escaped
299-
!! string is returned from [[json_get_string]]
300-
!! and similar routines. If true [default],
301-
!! then the string is returned unescaped.
302-
character(kind=CK,len=1),intent(in),optional :: comment_char !! If present, this character is used
303-
!! to denote comments in the JSON file,
304-
!! which will be ignored if present.
305-
!! Example: `!` or `#`.
283+
#include "json_initialize_arguments.inc"
306284

307285
call me%core%initialize(verbose,compact_reals,&
308286
print_signs,real_format,spaces_per_tab,&
@@ -311,19 +289,20 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
311289
case_sensitive_keys,&
312290
no_whitespace,&
313291
unescape_strings,&
314-
comment_char)
292+
comment_char,&
293+
use_rfc6901_paths)
315294

316295
end subroutine initialize_json_core_in_file
317296
!*****************************************************************************************
318297

319298
!*****************************************************************************************
320299
!>
321-
! Set the [[json_core]] for this [[json_file]].
300+
! Set the [[json_core(type)]] for this [[json_file]].
322301
!
323302
!@note: This does not destroy the data in the file.
324303
!
325304
!@note: This one is used if you want to initialize the file with
326-
! an already-existing [[json_core]] (presumably, this was already
305+
! an already-existing [[json_core(type)]] (presumably, this was already
327306
! initialized by a call to [[initialize_json_core]] or similar).
328307

329308
subroutine set_json_core_in_file(me,core)
@@ -340,7 +319,7 @@ end subroutine set_json_core_in_file
340319

341320
!*****************************************************************************************
342321
!>
343-
! Get a copy of the [[json_core]] in this [[json_file]].
322+
! Get a copy of the [[json_core(type)]] in this [[json_file]].
344323

345324
subroutine get_json_core_in_file(me,core)
346325

@@ -372,37 +351,15 @@ function initialize_json_file(p,verbose,compact_reals,&
372351
case_sensitive_keys,&
373352
no_whitespace,&
374353
unescape_strings,&
375-
comment_char) result(file_object)
354+
comment_char,&
355+
use_rfc6901_paths) result(file_object)
376356

377357
implicit none
378358

379359
type(json_file) :: file_object
380360
type(json_value),pointer,optional,intent(in) :: p !! `json_value` object to cast
381361
!! as a `json_file` object
382-
logical(LK),intent(in),optional :: verbose !! mainly useful for debugging (default is false)
383-
logical(LK),intent(in),optional :: compact_reals !! to compact the real number strings for output (default is true)
384-
logical(LK),intent(in),optional :: print_signs !! always print numeric sign (default is false)
385-
character(kind=CDK,len=*),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
386-
integer(IK),intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
387-
logical(LK),intent(in),optional :: strict_type_checking !! if true, no integer, double, or logical type
388-
!! conversions are done for the `get` routines
389-
!! (default is false)
390-
logical(LK),intent(in),optional :: trailing_spaces_significant !! for name and path comparisons, is trailing
391-
!! space to be considered significant.
392-
!! (default is false)
393-
logical(LK),intent(in),optional :: case_sensitive_keys !! for name and path comparisons, are they
394-
!! case sensitive. (default is true)
395-
logical(LK),intent(in),optional :: no_whitespace !! if true, printing the JSON structure is
396-
!! done without adding any non-significant
397-
!! spaces or linebreaks (default is false)
398-
logical(LK),intent(in),optional :: unescape_strings !! If false, then the raw escaped
399-
!! string is returned from [[json_get_string]]
400-
!! and similar routines. If true [default],
401-
!! then the string is returned unescaped.
402-
character(kind=CK,len=1),intent(in),optional :: comment_char !! If present, this character is used
403-
!! to denote comments in the JSON file,
404-
!! which will be ignored if present.
405-
!! Example: `!` or `#`.
362+
#include "json_initialize_arguments.inc"
406363

407364
call file_object%initialize(verbose,compact_reals,&
408365
print_signs,real_format,spaces_per_tab,&
@@ -411,7 +368,8 @@ function initialize_json_file(p,verbose,compact_reals,&
411368
case_sensitive_keys,&
412369
no_whitespace,&
413370
unescape_strings,&
414-
comment_char)
371+
comment_char,&
372+
use_rfc6901_paths)
415373

416374
if (present(p)) file_object%p => p
417375

@@ -422,7 +380,7 @@ end function initialize_json_file
422380
!> author: Jacob Williams
423381
! date: 4/26/2016
424382
!
425-
! Cast a [[json_value]] pointer and a [[json_core]] object
383+
! Cast a [[json_value]] pointer and a [[json_core(type)]] object
426384
! as a [[json_file(type)]] object.
427385

428386
function initialize_json_file_v2(json_value_object, json_core_object) &
@@ -448,8 +406,8 @@ end function initialize_json_file_v2
448406
! or will be reused to open a different file.
449407
! Otherwise a memory leak will occur.
450408
!
451-
! Optionally, also destroy the [[json_core]] instance (this
452-
! is not necessary to prevent memory leaks, since a [[json_core]]
409+
! Optionally, also destroy the [[json_core(type)]] instance (this
410+
! is not necessary to prevent memory leaks, since a [[json_core(type)]]
453411
! does not use pointers).
454412
!
455413
!### History
@@ -461,7 +419,7 @@ subroutine json_file_destroy(me,destroy_core)
461419
implicit none
462420

463421
class(json_file),intent(inout) :: me
464-
logical,intent(in),optional :: destroy_core !! to also destroy the [[json_core]].
422+
logical,intent(in),optional :: destroy_core !! to also destroy the [[json_core(type)]].
465423
!! default is to leave it as is.
466424

467425
if (associated(me%p)) call me%core%destroy(me%p)

src/json_initialize_arguments.inc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
logical(LK),intent(in),optional :: verbose !! mainly useful for debugging (default is false)
2+
logical(LK),intent(in),optional :: compact_reals !! to compact the real number strings for output (default is true)
3+
logical(LK),intent(in),optional :: print_signs !! always print numeric sign (default is false)
4+
character(kind=CDK,len=*),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
5+
integer(IK),intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
6+
logical(LK),intent(in),optional :: strict_type_checking !! if true, no integer, double, or logical type
7+
!! conversions are done for the `get` routines
8+
!! (default is false)
9+
logical(LK),intent(in),optional :: trailing_spaces_significant !! for name and path comparisons, is trailing
10+
!! space to be considered significant.
11+
!! (default is false)
12+
logical(LK),intent(in),optional :: case_sensitive_keys !! for name and path comparisons, are they
13+
!! case sensitive. (default is true)
14+
logical(LK),intent(in),optional :: no_whitespace !! if true, printing the JSON structure is
15+
!! done without adding any non-significant
16+
!! spaces or linebreaks (default is false)
17+
logical(LK),intent(in),optional :: unescape_strings !! If false, then the raw escaped
18+
!! string is returned from [[json_get_string]]
19+
!! and similar routines. If true [default],
20+
!! then the string is returned unescaped.
21+
character(kind=CK,len=1),intent(in),optional :: comment_char !! If present, this character is used
22+
!! to denote comments in the JSON file,
23+
!! which will be ignored if present.
24+
!! Example: `!` or `#`.
25+
logical(LK),intent(in),optional :: use_rfc6901_paths !! If true, then path values in the
26+
!! `get_by_path` routines are interpreted
27+
!! as RFC 6901 "JSON Pointer" paths.
28+
!! By default, this is False.

src/json_parameters.F90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module json_parameters
5050
character(kind=CK,len=*),parameter :: root = CK_'$' !! for [[json_get_by_path]]
5151
character(kind=CK,len=*),parameter :: this = CK_'@' !! for [[json_get_by_path]]
5252
character(kind=CK,len=*),parameter :: child = CK_'.' !! for [[json_get_by_path]]
53+
character(kind=CK,len=*),parameter :: tilde = CK_'~'
5354
character(kind=CK,len=*),parameter :: bspace = achar(8, kind=CK)
5455
character(kind=CK,len=*),parameter :: horizontal_tab = achar(9, kind=CK)
5556
character(kind=CK,len=*),parameter :: newline = achar(10, kind=CK)
@@ -120,7 +121,7 @@ module json_parameters
120121
integer(IK),parameter :: seq_chunk_size = 256_IK !! chunk size for reading sequential files
121122

122123
integer(IK),parameter :: pushed_char_size = 10_IK !! size for `pushed_char`
123-
!! array in [[json_core]]
124+
!! array in [[json_core(type)]]
124125

125126
end module json_parameters
126127
!*****************************************************************************************

0 commit comments

Comments
 (0)