Skip to content

Commit 0afb38e

Browse files
Merge pull request #224 from jacobwilliams/getpath
Getpath
2 parents 044baf7 + 8337f43 commit 0afb38e

File tree

5 files changed

+431
-60
lines changed

5 files changed

+431
-60
lines changed

files/inputs/test1.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"number": 1,
2525
"tf1": true,
2626
"tf2": false,
27+
"empty": null,
2728
"name": "Horatio",
2829
"array": [
2930
"1",

src/json_file_module.F90

+16-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
272272
strict_type_checking,&
273273
trailing_spaces_significant,&
274274
case_sensitive_keys,&
275-
no_whitespace)
275+
no_whitespace,&
276+
unescape_strings)
276277

277278
implicit none
278279

@@ -293,13 +294,18 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
293294
logical(LK),intent(in),optional :: no_whitespace !! if true, printing the JSON structure is
294295
!! done without adding any non-significant
295296
!! spaces or linebreaks (default is false)
297+
logical(LK),intent(in),optional :: unescape_strings !! If false, then the raw escaped
298+
!! string is returned from [[json_get_string]]
299+
!! and similar routines. If true [default],
300+
!! then the string is returned unescaped.
296301

297302
call me%core%initialize(verbose,compact_reals,&
298303
print_signs,real_format,spaces_per_tab,&
299304
strict_type_checking,&
300305
trailing_spaces_significant,&
301306
case_sensitive_keys,&
302-
no_whitespace)
307+
no_whitespace,&
308+
unescape_strings)
303309

304310
end subroutine initialize_json_core_in_file
305311
!*****************************************************************************************
@@ -358,7 +364,8 @@ function initialize_json_file(p,verbose,compact_reals,&
358364
strict_type_checking,&
359365
trailing_spaces_significant,&
360366
case_sensitive_keys,&
361-
no_whitespace) result(file_object)
367+
no_whitespace,&
368+
unescape_strings) result(file_object)
362369

363370
implicit none
364371

@@ -381,13 +388,18 @@ function initialize_json_file(p,verbose,compact_reals,&
381388
logical(LK),intent(in),optional :: no_whitespace !! if true, printing the JSON structure is
382389
!! done without adding any non-significant
383390
!! spaces or linebreaks (default is false)
391+
logical(LK),intent(in),optional :: unescape_strings !! If false, then the raw escaped
392+
!! string is returned from [[json_get_string]]
393+
!! and similar routines. If true [default],
394+
!! then the string is returned unescaped.
384395

385396
call file_object%initialize(verbose,compact_reals,&
386397
print_signs,real_format,spaces_per_tab,&
387398
strict_type_checking,&
388399
trailing_spaces_significant,&
389400
case_sensitive_keys,&
390-
no_whitespace)
401+
no_whitespace,&
402+
unescape_strings)
391403

392404
if (present(p)) file_object%p => p
393405

src/json_parameters.F90

+39-34
Original file line numberDiff line numberDiff line change
@@ -38,57 +38,57 @@ module json_parameters
3838
integer(IK),parameter :: json_string = 7 !! String JSON data type
3939

4040
!special JSON characters
41-
character(kind=CK,len=*),parameter :: space = ' '
42-
character(kind=CK,len=*),parameter :: start_object = '{'
43-
character(kind=CK,len=*),parameter :: end_object = '}'
44-
character(kind=CK,len=*),parameter :: start_array = '['
45-
character(kind=CK,len=*),parameter :: end_array = ']'
46-
character(kind=CK,len=*),parameter :: delimiter = ','
47-
character(kind=CK,len=*),parameter :: colon_char = ':'
48-
character(kind=CK,len=*),parameter :: start_array_alt = '(' !! for [[json_get_by_path]]
49-
character(kind=CK,len=*),parameter :: end_array_alt = ')' !! for [[json_get_by_path]]
50-
character(kind=CK,len=*),parameter :: root = '$' !! for [[json_get_by_path]]
51-
character(kind=CK,len=*),parameter :: this = '@' !! for [[json_get_by_path]]
52-
character(kind=CK,len=*),parameter :: child = '.' !! for [[json_get_by_path]]
53-
character(kind=CK,len=*),parameter :: bspace = achar(8)
54-
character(kind=CK,len=*),parameter :: horizontal_tab = achar(9)
55-
character(kind=CK,len=*),parameter :: newline = achar(10)
56-
character(kind=CK,len=*),parameter :: formfeed = achar(12)
57-
character(kind=CK,len=*),parameter :: carriage_return = achar(13)
58-
character(kind=CK,len=*),parameter :: quotation_mark = achar(34)
59-
character(kind=CK,len=*),parameter :: slash = achar(47)
60-
character(kind=CK,len=*),parameter :: backslash = achar(92)
41+
character(kind=CK,len=*),parameter :: space = CK_' '
42+
character(kind=CK,len=*),parameter :: start_object = CK_'{'
43+
character(kind=CK,len=*),parameter :: end_object = CK_'}'
44+
character(kind=CK,len=*),parameter :: start_array = CK_'['
45+
character(kind=CK,len=*),parameter :: end_array = CK_']'
46+
character(kind=CK,len=*),parameter :: delimiter = CK_','
47+
character(kind=CK,len=*),parameter :: colon_char = CK_':'
48+
character(kind=CK,len=*),parameter :: start_array_alt = CK_'(' !! for [[json_get_by_path]]
49+
character(kind=CK,len=*),parameter :: end_array_alt = CK_')' !! for [[json_get_by_path]]
50+
character(kind=CK,len=*),parameter :: root = CK_'$' !! for [[json_get_by_path]]
51+
character(kind=CK,len=*),parameter :: this = CK_'@' !! for [[json_get_by_path]]
52+
character(kind=CK,len=*),parameter :: child = CK_'.' !! for [[json_get_by_path]]
53+
character(kind=CK,len=*),parameter :: bspace = achar(8, kind=CK)
54+
character(kind=CK,len=*),parameter :: horizontal_tab = achar(9, kind=CK)
55+
character(kind=CK,len=*),parameter :: newline = achar(10, kind=CK)
56+
character(kind=CK,len=*),parameter :: formfeed = achar(12, kind=CK)
57+
character(kind=CK,len=*),parameter :: carriage_return = achar(13, kind=CK)
58+
character(kind=CK,len=*),parameter :: quotation_mark = achar(34, kind=CK)
59+
character(kind=CK,len=*),parameter :: slash = achar(47, kind=CK)
60+
character(kind=CK,len=*),parameter :: backslash = achar(92, kind=CK)
6161

6262
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E26.16E4)'
6363
!! default real number format statement (for writing real values to strings and files).
6464
!! Note that this can be overridden by calling [[json_initialize]].
6565

66-
character(kind=CK,len=*),parameter :: star = '*' !! for invalid numbers and
67-
!! list-directed real output
66+
character(kind=CK,len=*),parameter :: star = CK_'*' !! for invalid numbers and
67+
!! list-directed real output
6868

6969
#if defined __GFORTRAN__
7070
!not parameters due to gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
71-
character(kind=CK,len=26),protected :: upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
72-
character(kind=CK,len=26),protected :: lower = 'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
71+
character(kind=CK,len=26),protected :: upper = CK_'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
72+
character(kind=CK,len=26),protected :: lower = CK_'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
7373
#else
74-
character(kind=CK,len=*),parameter :: upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
75-
character(kind=CK,len=*),parameter :: lower = 'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
74+
character(kind=CK,len=*),parameter :: upper = CK_'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
75+
character(kind=CK,len=*),parameter :: lower = CK_'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
7676
#endif
7777

7878
#if defined __GFORTRAN__
7979
!not parameters due to gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
80-
character(kind=CK,len=4),protected :: null_str = 'null' !! JSON Null variable string
81-
character(kind=CK,len=4),protected :: true_str = 'true' !! JSON logical True string
82-
character(kind=CK,len=5),protected :: false_str = 'false' !! JSON logical False string
80+
character(kind=CK,len=4),protected :: null_str = CK_'null' !! JSON Null variable string
81+
character(kind=CK,len=4),protected :: true_str = CK_'true' !! JSON logical True string
82+
character(kind=CK,len=5),protected :: false_str = CK_'false' !! JSON logical False string
8383
#else
84-
character(kind=CK,len=*),parameter :: null_str = 'null' !! JSON Null variable string
85-
character(kind=CK,len=*),parameter :: true_str = 'true' !! JSON logical True string
86-
character(kind=CK,len=*),parameter :: false_str = 'false' !! JSON logical False string
84+
character(kind=CK,len=*),parameter :: null_str = CK_'null' !! JSON Null variable string
85+
character(kind=CK,len=*),parameter :: true_str = CK_'true' !! JSON logical True string
86+
character(kind=CK,len=*),parameter :: false_str = CK_'false' !! JSON logical False string
8787
#endif
8888

8989
integer, private :: i_ !! just a counter for `control_chars` array
9090
character(kind=CK,len=*),dimension(32),parameter :: control_chars = &
91-
[(achar(i_),i_=1,31), achar(127)] !! Control characters, possibly in unicode
91+
[(achar(i_,kind=CK),i_=1,31), achar(127,kind=CK)] !! Control characters, possibly in unicode
9292

9393
!find out the precision of the floating point number system
9494
!and set safety factors
@@ -108,14 +108,19 @@ module json_parameters
108108
!! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra
109109
character(kind=CDK,len=*),parameter :: int_fmt = '(ss,I0)' !! minimum width format for integers
110110

111+
integer(IK),parameter :: max_integer_str_len = 256 !! maximum string length of an integer.
112+
!! This is totally arbitrary (any way
113+
!! to get the compiler to tell us this?)
114+
111115
integer(IK),parameter :: chunk_size = 100_IK !! for allocatable strings: allocate chunks of this size
112116
integer(IK),parameter :: unit2str = -1_IK !! unit number to cause stuff to be
113117
!! output to strings rather than files.
114118
!! See 9.5.6.12 in the F2003/08 standard
115119

116120
integer(IK),parameter :: seq_chunk_size = 256_IK !! chunk size for reading sequential files
117121

118-
integer(IK),parameter :: pushed_char_size = 10_IK !! magic number
122+
integer(IK),parameter :: pushed_char_size = 10_IK !! size for `pushed_char`
123+
!! array in [[json_core]]
119124

120125
end module json_parameters
121126
!*****************************************************************************************

0 commit comments

Comments
 (0)