Skip to content

Commit 0f1ebff

Browse files
committed
Merge pull request #192 from jacobwilliams/name-search
Name searching options
2 parents 290f83d + ba95e6a commit 0f1ebff

File tree

7 files changed

+302
-76
lines changed

7 files changed

+302
-76
lines changed

src/json_file_module.F90

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,31 @@ end subroutine json_file_print_error_message
255255

256256
subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
257257
print_signs,real_format,spaces_per_tab,&
258-
strict_type_checking)
258+
strict_type_checking,&
259+
trailing_spaces_significant,&
260+
case_sensitive_keys)
259261

260262
implicit none
261263

262264
class(json_file),intent(inout) :: me
263265
logical(LK),intent(in),optional :: verbose !! mainly useful for debugging (default is false)
264266
logical(LK),intent(in),optional :: compact_reals !! to compact the real number strings for output (default is true)
265267
logical(LK),intent(in),optional :: print_signs !! always print numeric sign (default is false)
266-
character(len=*,kind=CDK),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
267-
integer,intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
268+
character(kind=CDK,len=*),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
269+
integer(IK),intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
268270
logical(LK),intent(in),optional :: strict_type_checking !! if true, no integer, double, or logical type
269271
!! conversions are done for the `get` routines
270272
!! (default is false)
273+
logical(LK),intent(in),optional :: trailing_spaces_significant !! for name and path comparisons, is trailing
274+
!! space to be considered significant.
275+
logical(LK),intent(in),optional :: case_sensitive_keys !! for name and path comparisons, are they
276+
!! case sensitive.
271277

272278
call me%json%initialize(verbose,compact_reals,&
273279
print_signs,real_format,spaces_per_tab,&
274-
strict_type_checking)
280+
strict_type_checking,&
281+
trailing_spaces_significant,&
282+
case_sensitive_keys)
275283

276284
end subroutine initialize_json_core_in_file
277285
!*****************************************************************************************
@@ -289,7 +297,9 @@ end subroutine initialize_json_core_in_file
289297

290298
function initialize_json_file(p,verbose,compact_reals,&
291299
print_signs,real_format,spaces_per_tab,&
292-
strict_type_checking) result(file_object)
300+
strict_type_checking,&
301+
trailing_spaces_significant,&
302+
case_sensitive_keys) result(file_object)
293303

294304
implicit none
295305

@@ -299,15 +309,21 @@ function initialize_json_file(p,verbose,compact_reals,&
299309
logical(LK),intent(in),optional :: verbose !! mainly useful for debugging (default is false)
300310
logical(LK),intent(in),optional :: compact_reals !! to compact the real number strings for output (default is true)
301311
logical(LK),intent(in),optional :: print_signs !! always print numeric sign (default is false)
302-
character(len=*,kind=CDK),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
303-
integer,intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
312+
character(kind=CDK,len=*),intent(in),optional :: real_format !! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES'
313+
integer(IK),intent(in),optional :: spaces_per_tab !! number of spaces per tab for indenting (default is 2)
304314
logical(LK),intent(in),optional :: strict_type_checking !! if true, no integer, double, or logical type
305315
!! conversions are done for the `get` routines
306316
!! (default is false)
317+
logical(LK),intent(in),optional :: trailing_spaces_significant !! for name and path comparisons, is trailing
318+
!! space to be considered significant.
319+
logical(LK),intent(in),optional :: case_sensitive_keys !! for name and path comparisons, are they
320+
!! case sensitive.
307321

308322
call file_object%initialize(verbose,compact_reals,&
309323
print_signs,real_format,spaces_per_tab,&
310-
strict_type_checking)
324+
strict_type_checking,&
325+
trailing_spaces_significant,&
326+
case_sensitive_keys)
311327

312328
if (present(p)) file_object%p => p
313329

src/json_parameters.F90

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,34 @@ module json_parameters
4949
character(kind=CK,len=*),parameter,public :: star = '*' !! for invalid numbers and
5050
!! list-directed real output
5151

52-
!these are default character kind:
53-
character(kind=CDK,len=*),parameter,public :: upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
54-
!! uppercase characters
55-
character(kind=CDK,len=*),parameter,public :: lower = 'abcdefghijklmnopqrstuvwxyz'
56-
!! lowercase characters
57-
58-
!These were parameters, but gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
59-
!necessitates moving them here to be variables
52+
#if defined __GFORTRAN__
53+
!not parameters due to gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
54+
character(kind=CK,len=26),protected :: upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
55+
character(kind=CK,len=26),protected :: lower = 'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
56+
#else
57+
character(kind=CK,len=*),parameter,public :: upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' !! uppercase characters
58+
character(kind=CK,len=*),parameter,public :: lower = 'abcdefghijklmnopqrstuvwxyz' !! lowercase characters
59+
#endif
60+
61+
#if defined __GFORTRAN__
62+
!not parameters due to gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
6063
character(kind=CK,len=4),protected :: null_str = 'null' !! JSON Null variable string
6164
character(kind=CK,len=4),protected :: true_str = 'true' !! JSON logical True string
6265
character(kind=CK,len=5),protected :: false_str = 'false' !! JSON logical False string
66+
#else
67+
character(kind=CK,len=*),parameter,public :: null_str = 'null' !! JSON Null variable string
68+
character(kind=CK,len=*),parameter,public :: true_str = 'true' !! JSON logical True string
69+
character(kind=CK,len=*),parameter,public :: false_str = 'false' !! JSON logical False string
70+
#endif
6371

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

6876
!find out the precision of the floating point number system
6977
!and set safety factors
70-
integer(IK),parameter :: rp_safety_factor = 1
71-
integer(IK),parameter :: rp_addl_safety = 1
78+
integer(IK),parameter :: rp_safety_factor = 1_IK
79+
integer(IK),parameter :: rp_addl_safety = 1_IK
7280
integer(IK),parameter :: real_precision = rp_safety_factor*precision(1.0_RK) + &
7381
rp_addl_safety
7482

@@ -83,14 +91,14 @@ module json_parameters
8391
!! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra
8492
character(kind=CDK,len=*),parameter :: int_fmt = '(ss,I0)' !! minimum width format for integers
8593

86-
integer(IK),parameter :: chunk_size = 100 !! for allocatable strings: allocate chunks of this size
87-
integer(IK),parameter :: unit2str = -1 !! unit number to cause stuff to be
88-
!! output to strings rather than files.
89-
!! See 9.5.6.12 in the F2003/08 standard
94+
integer(IK),parameter :: chunk_size = 100_IK !! for allocatable strings: allocate chunks of this size
95+
integer(IK),parameter :: unit2str = -1_IK !! unit number to cause stuff to be
96+
!! output to strings rather than files.
97+
!! See 9.5.6.12 in the F2003/08 standard
9098

91-
integer(IK),parameter,public :: seq_chunk_size = 256 !! chunk size for reading sequential files
99+
integer(IK),parameter,public :: seq_chunk_size = 256_IK !! chunk size for reading sequential files
92100

93-
integer(IK),parameter,public :: pushed_char_size = 10 !! magic number
101+
integer(IK),parameter,public :: pushed_char_size = 10_IK !! magic number
94102

95103
end module json_parameters
96104
!*****************************************************************************************

src/json_string_utilities.F90

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module json_string_utilities
6565
public :: to_unicode
6666
public :: escape_string
6767
public :: unescape_string
68-
public :: lowercase_character
68+
public :: lowercase_string
6969

7070
contains
7171
!*****************************************************************************************
@@ -154,6 +154,7 @@ subroutine compact_real_string(str)
154154

155155
character(kind=CK,len=len(str)) :: significand, expnt
156156
character(kind=CK,len=2) :: separator
157+
157158
integer(IK) :: exp_start,decimal_pos,sig_trim,exp_trim,i
158159

159160
str = adjustl(str)
@@ -523,7 +524,7 @@ end function to_uni_vec
523524
!
524525
! `CK`//`CDK` operator.
525526

526-
function ucs4_join_default(ucs4_str,def_str) result(res)
527+
pure function ucs4_join_default(ucs4_str,def_str) result(res)
527528

528529
implicit none
529530

@@ -541,7 +542,7 @@ end function ucs4_join_default
541542
!
542543
! `CDK`//`CK` operator.
543544

544-
function default_join_ucs4(def_str,ucs4_str) result(res)
545+
pure function default_join_ucs4(def_str,ucs4_str) result(res)
545546

546547
implicit none
547548

@@ -559,7 +560,7 @@ end function default_join_ucs4
559560
!
560561
! `CK`==`CDK` operator.
561562

562-
function ucs4_comp_default(ucs4_str,def_str) result(res)
563+
pure elemental function ucs4_comp_default(ucs4_str,def_str) result(res)
563564

564565
implicit none
565566

@@ -577,7 +578,7 @@ end function ucs4_comp_default
577578
!
578579
! `CDK`==`CK` operator.
579580

580-
function default_comp_ucs4(def_str,ucs4_str) result(res)
581+
pure elemental function default_comp_ucs4(def_str,ucs4_str) result(res)
581582

582583
implicit none
583584

@@ -595,7 +596,7 @@ end function default_comp_ucs4
595596
!
596597
! `CK`/=`CDK` operator.
597598

598-
function ucs4_neq_default(ucs4_str,def_str) result(res)
599+
pure elemental function ucs4_neq_default(ucs4_str,def_str) result(res)
599600

600601
implicit none
601602

@@ -613,7 +614,7 @@ end function ucs4_neq_default
613614
!
614615
! `CDK`/=`CK` operator.
615616

616-
function default_neq_ucs4(def_str,ucs4_str) result(res)
617+
pure elemental function default_neq_ucs4(def_str,ucs4_str) result(res)
617618

618619
implicit none
619620

@@ -627,23 +628,51 @@ end function default_neq_ucs4
627628
!*****************************************************************************************
628629

629630
!*****************************************************************************************
630-
!>
631-
! Return the lowercase version of the character.
631+
!> author: Jacob Williams
632+
!
633+
! Return the lowercase version of the `CK` character.
632634

633-
pure function lowercase_character(c) result(c_lower)
635+
pure elemental function lowercase_character(c) result(c_lower)
634636

635637
implicit none
636638

637-
character(kind=CDK,len=1),intent(in) :: c
638-
character(kind=CDK,len=1) :: c_lower
639+
character(kind=CK,len=1),intent(in) :: c
640+
character(kind=CK,len=1) :: c_lower
639641

640-
integer :: i !! index in array
642+
integer :: i !! index in uppercase array
641643

642644
i = index(upper,c)
643645
c_lower = merge(lower(i:i),c,i>0)
644646

645647
end function lowercase_character
646648
!*****************************************************************************************
647649

650+
!*****************************************************************************************
651+
!> author: Jacob Williams
652+
!
653+
! Returns lowercase version of the `CK` string.
654+
655+
pure elemental function lowercase_string(str) result(s_lower)
656+
657+
implicit none
658+
659+
character(kind=CK,len=*),intent(in) :: str !! input string
660+
character(kind=CK,len=(len(str))) :: s_lower !! lowercase version of the string
661+
662+
integer :: i !! counter
663+
integer :: n !! length of input string
664+
665+
s_lower = ''
666+
n = len_trim(str)
667+
668+
if (n>0) then
669+
do concurrent (i=1:n)
670+
s_lower(i:i) = lowercase_character(str(i:i))
671+
end do
672+
end if
673+
674+
end function lowercase_string
675+
!*****************************************************************************************
676+
648677
end module json_string_utilities
649678
!*****************************************************************************************

0 commit comments

Comments
 (0)