Skip to content

Commit 7a42686

Browse files
committedApr 20, 2016
Main json_module now renames the kind variables to avoid namespace pollution. It also now exports the CK/CDK operators when using unicode.
Also added CK/=CDK operators for completeness. Various documentation updates. Tests removed from FORD documentation to avoid clutter.
1 parent e77cfe1 commit 7a42686

19 files changed

+113
-58
lines changed
 

‎json-fortran.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ display: public
2020
private
2121
source: true
2222
graph: true
23+
exclude_dir: tests
2324
extra_mods: iso_fortran_env:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html
24-
md_extensions: markdown.extensions.toc(anchorlink=True)
25-
markdown.extensions.smarty(smart_quotes=False)
25+
md_extensions: markdown.extensions.smarty(smart_quotes=False)
2626
---
2727

2828
--------------------

‎src/json_macros.inc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
!*****************************************************************************************
2-
!>
3-
! JSON-Fortran preprocessor macros.
1+
! JSON-Fortran preprocessor macros.
42
!
5-
!## License
6-
! * JSON-Fortran is released under a BSD-style license.
7-
! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
8-
! file for details.
3+
! License
4+
! JSON-Fortran is released under a BSD-style license.
5+
! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
6+
! file for details.
97

108
!*********************************************************
119
! File encoding preprocessor macro.

‎src/json_module.F90

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,32 @@
44
!
55
! A Fortran 2008 JSON (JavaScript Object Notation) API.
66
!
7-
! This module provides access to [[json_kinds]], [[json_value_module]] and
8-
! [[json_file_module]]. Either one can be used separately, or all can be
9-
! used by using this module.
7+
! This module provides access to [[json_value_module]] and
8+
! [[json_file_module]]. For normal JSON-Fortran use, using this module
9+
! is all that is necessary.
10+
!
11+
! Note that this module renames the kind definition variables from [[json_kinds]]
12+
! from [`RK`, `IK`, `LK`, `CK`, and `CDK`] to [`json_RK`, `json_IK`, `json_LK`,
13+
! `json_CK`, and `json_CDK`] so as to avoid namespace pollution with short
14+
! variable names.
15+
!
16+
#ifdef USE_UCS4
17+
#pragma push_macro("USE_UCS4")
18+
#undef USE_UCS4
19+
! Since ```USE_UCS4``` **is** defined, this module also exports the
20+
! operators `==`, `/=`, and `//` from [[json_string_utilities]] for
21+
! `CK` and `CDK` operations.
22+
#pragma pop_macro("USE_UCS4")
23+
#endif
1024
!
1125
!## License
1226
! * JSON-Fortran is released under a BSD-style license.
1327
! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE)
1428
! file for details.
1529
!
1630
!## History
17-
! * Joseph A. Levin : March 2012 : Original FSON code [retrieved on 12/2/2013].
31+
! * Joseph A. Levin : March 2012 : Original [FSON](https://github.com/josephalevin/fson)
32+
! code [retrieved on 12/2/2013].
1833
! * Jacob Williams : 2/8/2014 : Extensive modifications to the original FSON code.
1934
! The original F95 code was split into four files:
2035
! fson_path_m.f95, fson_string_m.f95, fson_value_m.f95, and fson.f95.
@@ -34,7 +49,16 @@
3449

3550
module json_module
3651

37-
use json_kinds
52+
use json_kinds, only: json_RK => RK, &
53+
json_IK => IK, &
54+
json_LK => LK, &
55+
json_CK => CK, &
56+
json_CDK => CDK
57+
#ifdef USE_UCS4
58+
use json_string_utilities, only: operator(==),&
59+
operator(//),&
60+
operator(/=)
61+
#endif
3862
use json_value_module
3963
use json_file_module
4064

‎src/json_parameters.F90

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ module json_parameters
4343
character(kind=CK,len=*),parameter :: backslash = achar(92)
4444

4545
character(kind=CDK,len=*),parameter,public :: default_real_fmt = '(ss,E26.16E4)'
46-
!! default real number format statement
46+
!! default real number format statement (for writing real values to strings and files).
47+
!! Note that this can be overridden by calling [[json_initialize]].
4748

4849
character(kind=CK,len=*),parameter,public :: star = '*' !! for invalid numbers and
4950
!! list-directed real output
@@ -56,9 +57,9 @@ module json_parameters
5657

5758
!These were parameters, but gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
5859
!necessitates moving them here to be variables
59-
character(kind=CK,len=4),protected :: null_str = 'null'
60-
character(kind=CK,len=4),protected :: true_str = 'true'
61-
character(kind=CK,len=5),protected :: false_str = 'false'
60+
character(kind=CK,len=4),protected :: null_str = 'null' !! JSON Null variable string
61+
character(kind=CK,len=4),protected :: true_str = 'true' !! JSON logical True string
62+
character(kind=CK,len=5),protected :: false_str = 'false' !! JSON logical False string
6263

6364
integer, private :: i_ !! just a counter for control_chars array
6465
character(kind=CK,len=*),dimension(32),parameter :: control_chars = &

‎src/json_string_utilities.F90

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ module json_string_utilities
4040

4141
!******************************************************
4242
!>
43-
! Provide a string comparison operator that works
43+
! Provide a string `==` operator that works
4444
! with mixed kinds
4545
interface operator(==)
4646
module procedure ucs4_comp_default, default_comp_ucs4
4747
end interface
4848
public :: operator(==)
4949
!******************************************************
50+
51+
!******************************************************
52+
!>
53+
! Provide a string `/=` operator that works
54+
! with mixed kinds
55+
interface operator(/=)
56+
module procedure ucs4_neq_default, default_neq_ucs4
57+
end interface
58+
public :: operator(/=)
59+
!******************************************************
5060
#endif
5161

5262
public :: integer_to_string
@@ -370,7 +380,7 @@ end function to_uni_vec
370380
!*****************************************************************************************
371381
!> author: Izaak Beekman
372382
!
373-
! CK//CDK operator.
383+
! `CK`//`CDK` operator.
374384

375385
function ucs4_join_default(ucs4_str,def_str) result(res)
376386

@@ -388,7 +398,7 @@ end function ucs4_join_default
388398
!*****************************************************************************************
389399
!> author: Izaak Beekman
390400
!
391-
! CDK//CK operator.
401+
! `CDK`//`CK` operator.
392402

393403
function default_join_ucs4(def_str,ucs4_str) result(res)
394404

@@ -406,7 +416,7 @@ end function default_join_ucs4
406416
!*****************************************************************************************
407417
!> author: Izaak Beekman
408418
!
409-
! CK==CDK operator.
419+
! `CK`==`CDK` operator.
410420

411421
function ucs4_comp_default(ucs4_str,def_str) result(res)
412422

@@ -424,7 +434,7 @@ end function ucs4_comp_default
424434
!*****************************************************************************************
425435
!> author: Izaak Beekman
426436
!
427-
! CDK==CK operator.
437+
! `CDK`==`CK` operator.
428438

429439
function default_comp_ucs4(def_str,ucs4_str) result(res)
430440

@@ -439,6 +449,42 @@ function default_comp_ucs4(def_str,ucs4_str) result(res)
439449
end function default_comp_ucs4
440450
!*****************************************************************************************
441451

452+
!*****************************************************************************************
453+
!> author: Jacob Williams
454+
!
455+
! `CK`/=`CDK` operator.
456+
457+
function ucs4_neq_default(ucs4_str,def_str) result(res)
458+
459+
implicit none
460+
461+
character(kind=CK, len=*), intent(in) :: ucs4_str
462+
character(kind=CDK,len=*), intent(in) :: def_str
463+
logical(LK) :: res
464+
465+
res = ( ucs4_str /= to_unicode(def_str) )
466+
467+
end function ucs4_neq_default
468+
!*****************************************************************************************
469+
470+
!*****************************************************************************************
471+
!> author: Jacob Williams
472+
!
473+
! `CDK`/=`CK` operator.
474+
475+
function default_neq_ucs4(def_str,ucs4_str) result(res)
476+
477+
implicit none
478+
479+
character(kind=CDK,len=*), intent(in) :: def_str
480+
character(kind=CK, len=*), intent(in) :: ucs4_str
481+
logical(LK) :: res
482+
483+
res = (to_unicode(def_str) /= ucs4_str)
484+
485+
end function default_neq_ucs4
486+
!*****************************************************************************************
487+
442488
!*****************************************************************************************
443489
!>
444490
! Return the lowercase version of the character.

‎src/tests/jf_test_1.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
module jf_test_1_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

@@ -29,7 +28,7 @@ subroutine test_1(error_cnt)
2928
type(json_core) :: core !! factory for manipulating `json_value` pointers
3029
integer,intent(out) :: error_cnt
3130
integer :: ival
32-
character(kind=CK,len=:),allocatable :: cval
31+
character(kind=json_CK,len=:),allocatable :: cval
3332
real(wp) :: rval
3433
logical :: found
3534

‎src/tests/jf_test_10.f90

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module jf_test_10_mod
88

9-
use json_kinds
109
use json_module
1110
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1211

@@ -25,15 +24,15 @@ subroutine test_10(error_cnt)
2524

2625
integer,intent(out) :: error_cnt
2726

28-
character(kind=CK,len=256),dimension(:),allocatable :: str_vec
27+
character(kind=json_CK,len=256),dimension(:),allocatable :: str_vec
2928
type(json_file) :: f,f2
3029
type(json_value),pointer :: p
3130
type(json_core) :: json !! factory for manipulating `json_value` pointers
32-
character(kind=CK,len=:),allocatable :: str,name
31+
character(kind=json_CK,len=:),allocatable :: str,name
3332
logical :: found,lval
3433
integer :: var_type,n_children
3534

36-
character(kind=CDK,len=*),parameter :: json_str = '{ "blah": 123 }'
35+
character(kind=json_CDK,len=*),parameter :: json_str = '{ "blah": 123 }'
3736

3837
error_cnt = 0
3938
call json%initialize()

‎src/tests/jf_test_11.F90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module jf_test_11_mod
88

9-
use json_kinds
109
use json_module
1110
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1211

@@ -27,7 +26,7 @@ subroutine test_11(error_cnt)
2726
implicit none
2827

2928
integer,intent(out) :: error_cnt
30-
character(kind=CK,len=:),allocatable :: cval
29+
character(kind=json_CK,len=:),allocatable :: cval
3130
type(json_file) :: json !the JSON structure read from the file:
3231
# ifdef USE_UCS4
3332
type(json_file) :: clone

‎src/tests/jf_test_12.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
module jf_test_12_mod
88

9-
use json_kinds
10-
use json_module
9+
use json_module, CK => json_CK
1110
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1211

1312
implicit none

‎src/tests/jf_test_13.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module jf_test_13_mod
88

9-
use json_kinds
109
use json_module
1110
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1211

@@ -22,8 +21,8 @@ subroutine test_13(error_cnt)
2221

2322
integer,intent(out) :: error_cnt !! report number of errors to caller
2423

25-
type(json_file) :: my_file
26-
character(kind=CK,len=:),allocatable :: str
24+
type(json_file) :: my_file
25+
character(kind=json_CK,len=:),allocatable :: str
2726
integer :: i
2827

2928
character(len=2),dimension(5),parameter :: fmts=['g ','e ','en','es','* ']

‎src/tests/jf_test_14.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module jf_test_14_mod
88

9-
use json_kinds
109
use json_module
1110
use, intrinsic :: iso_fortran_env , only: error_unit,output_unit
1211

@@ -84,7 +83,7 @@ subroutine rename(json,p,finished) !! change all "name" variable values to "Fre
8483
logical,intent(out) :: finished
8584

8685
integer :: var_type
87-
character(kind=CK,len=:),allocatable :: str
86+
character(kind=json_CK,len=:),allocatable :: str
8887
logical :: found
8988

9089
!get info about this variable:

‎src/tests/jf_test_2.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
!*****************************************************************************************
22
!>
3-
! Module for the second unit test.
3+
! Module for the second unit test.
44
!
55
!# HISTORY
66
! * Izaak Beekman : 2/18/2015 : Created (refactoried original json_example.f90 file)
77

88
module jf_test_2_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

@@ -30,7 +29,7 @@ subroutine test_2(error_cnt)
3029
type(json_value),pointer :: p, inp, traj, p_tmp, p_integer_array, p_clone
3130

3231
integer :: iunit
33-
character(kind=CK,len=:),allocatable :: name
32+
character(kind=json_CK,len=:),allocatable :: name
3433
integer :: ival,ival_clone
3534
logical :: found
3635

‎src/tests/jf_test_3.f90

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
module jf_test_3_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

@@ -26,11 +25,11 @@ subroutine test_3(error_cnt)
2625

2726
integer,intent(out) :: error_cnt
2827
integer :: ival
29-
character(kind=CK,len=:),allocatable :: cval
28+
character(kind=json_CK,len=:),allocatable :: cval
3029
real(wp) :: rval
3130
type(json_file) :: json !the JSON structure read from the file:
3231
integer :: i
33-
character(kind=CK,len=10) :: str
32+
character(kind=json_CK,len=10) :: str
3433
real(wp),dimension(:),allocatable :: rvec
3534

3635
error_cnt = 0
@@ -136,6 +135,6 @@ program jf_test_3
136135
n_errors = 0
137136
call test_3(n_errors)
138137
if (n_errors /= 0) stop 1
139-
138+
140139
end program jf_test_3
141140
!*****************************************************************************************

‎src/tests/jf_test_4.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
module jf_test_4_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

@@ -34,8 +33,8 @@ subroutine test_4(error_cnt)
3433
type(json_core) :: core !! factory for manipulating `json_value` pointers
3534

3635
integer :: i
37-
character(kind=CK,len=10) :: istr
38-
character(kind=CK,len=:),allocatable :: string
36+
character(kind=json_CK,len=10) :: istr
37+
character(kind=json_CK,len=:),allocatable :: string
3938

4039
error_cnt = 0
4140
call core%initialize()

‎src/tests/jf_test_5.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
module jf_test_5_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

‎src/tests/jf_test_6.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
!*****************************************************************************************
22
!>
3-
! Module for the sixth unit test.
3+
! Module for the sixth unit test.
44
!
55
!# HISTORY
66
! * Izaak Beekman : 2/18/2015 : Created (refactoried original json_example.f90 file)
77

88
module jf_test_6_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

‎src/tests/jf_test_7.f90

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
!*****************************************************************************************
22
!>
3-
! Module for the seventh unit test.
3+
! Module for the seventh unit test.
44
!
55
!# HISTORY
66
! * Izaak Beekman : 2/18/2015 : Created (refactoried original json_example.f90 file)
77

88
module jf_test_7_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

@@ -26,8 +25,8 @@ subroutine test_7(error_cnt)
2625
type(json_core) :: json !! factory for manipulating `json_value` pointers
2726
type(json_value),pointer :: root,a,b,c,d,e,e1,e2,escaped_string,p
2827
logical :: found
29-
character(kind=CK,len=1), dimension(:), allocatable :: strvec
30-
character(kind=CK,len=:), allocatable :: string
28+
character(kind=json_CK,len=1), dimension(:), allocatable :: strvec
29+
character(kind=json_CK,len=:), allocatable :: string
3130

3231
found=.false.
3332
error_cnt = 0

‎src/tests/jf_test_8.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
!*****************************************************************************************
22
!>
3-
! Module for the eighth unit test.
3+
! Module for the eighth unit test.
44
!
55
!# HISTORY
66
! * Izaak Beekman : 2/18/2015 : Created (refactoried original json_example.f90 file)
77

88
module jf_test_8_mod
99

10-
use json_kinds
1110
use json_module
1211
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1312

‎src/tests/jf_test_9.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module jf_test_9_mod
88

9-
use json_kinds
109
use json_module
1110
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1211

0 commit comments

Comments
 (0)
Please sign in to comment.