Skip to content

Commit e77cfe1

Browse files
committed
Calls to initialize() are now optional. If not called, a default real format statement is used. Fixes #171.
Documentation updates.
1 parent 7d7669a commit e77cfe1

File tree

5 files changed

+104
-63
lines changed

5 files changed

+104
-63
lines changed

src/json_module.F90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
!
55
! A Fortran 2008 JSON (JavaScript Object Notation) API.
66
!
7-
! This module provides access to the [[json_value_module]] and [[json_file_module]],
8-
! Either one can be used separately, or both can be used by using this module.
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.
910
!
1011
!## License
1112
! * JSON-Fortran is released under a BSD-style license.
@@ -33,9 +34,9 @@
3334

3435
module json_module
3536

37+
use json_kinds
3638
use json_value_module
3739
use json_file_module
38-
use json_string_utilities
3940

4041
implicit none
4142

src/json_parameters.F90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,18 @@ module json_parameters
4242
character(kind=CK,len=*),parameter :: slash = achar(47)
4343
character(kind=CK,len=*),parameter :: backslash = achar(92)
4444

45+
character(kind=CDK,len=*),parameter,public :: default_real_fmt = '(ss,E26.16E4)'
46+
!! default real number format statement
47+
4548
character(kind=CK,len=*),parameter,public :: star = '*' !! for invalid numbers and
4649
!! list-directed real output
4750

51+
!these are default character kind:
52+
character(kind=CDK,len=*),parameter,public :: upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
53+
!! uppercase characters
54+
character(kind=CDK,len=*),parameter,public :: lower = 'abcdefghijklmnopqrstuvwxyz'
55+
!! lowercase characters
56+
4857
!These were parameters, but gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
4958
!necessitates moving them here to be variables
5059
character(kind=CK,len=4),protected :: null_str = 'null'

src/json_string_utilities.F90

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module json_string_utilities
5454
public :: valid_json_hex
5555
public :: to_unicode
5656
public :: escape_string
57+
public :: lowercase_character
5758

5859
contains
5960
!*****************************************************************************************
@@ -306,7 +307,8 @@ pure function valid_json_hex(str) result(valid)
306307
logical(LK) :: valid !! is str a value 4-digit hex string
307308
character(kind=CK,len=*),intent(in) :: str !! the string to check.
308309

309-
integer(IK) :: n,i
310+
integer(IK) :: n !! length of `str`
311+
integer(IK) :: i !! counter
310312

311313
!an array of the valid hex characters:
312314
character(kind=CK,len=1),dimension(22),parameter :: valid_chars = &
@@ -437,5 +439,24 @@ function default_comp_ucs4(def_str,ucs4_str) result(res)
437439
end function default_comp_ucs4
438440
!*****************************************************************************************
439441

442+
!*****************************************************************************************
443+
!>
444+
! Return the lowercase version of the character.
445+
446+
pure function lowercase_character(c) result(c_lower)
447+
448+
implicit none
449+
450+
character(kind=CDK,len=1),intent(in) :: c
451+
character(kind=CDK,len=1) :: c_lower
452+
453+
integer :: i !! index in array
454+
455+
i = index(upper,c)
456+
c_lower = merge(lower(i:i),c,i>0)
457+
458+
end function lowercase_character
459+
!*****************************************************************************************
460+
440461
end module json_string_utilities
441462
!*****************************************************************************************

0 commit comments

Comments
 (0)