Skip to content

json file remove #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# --compiler : gnu or gfortran for gfortran, intel or ifort for intel compiler
# A custom compiler may also be specified here, e.g. ftn
#
# --cflags : Enter any aditiol/custom compiler flags here and make sure they are
# --cflags : Enter any additional/custom compiler flags here and make sure they are
# properly quoted
#
# --help : Print a usage message and exit.
Expand Down
44 changes: 44 additions & 0 deletions src/json_file_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ module json_file_module
json_file_update_string_val_ascii
#endif

!>
! Remove a variable from a [[json_file(type)]]
! by specifying the path.
generic,public :: remove => MAYBEWRAP(json_file_remove)

!traverse
procedure,public :: traverse => json_file_traverse

Expand Down Expand Up @@ -244,6 +249,9 @@ module json_file_module
procedure :: json_file_update_string_val_ascii
#endif

!remove:
procedure :: MAYBEWRAP(json_file_remove)

!print_file:
procedure :: json_file_print_to_console
procedure :: json_file_print_1
Expand Down Expand Up @@ -2192,6 +2200,42 @@ subroutine json_file_traverse(me,traverse_callback)
end subroutine json_file_traverse
!*****************************************************************************************

!*****************************************************************************************
!> author: Jacob Williams
! date: 7/7/2018
!
! Remove a variable from a JSON file.
!
!@note This is just a wrapper to [[remove_if_present]].

subroutine json_file_remove(me,path)

implicit none

class(json_file),intent(inout) :: me
character(kind=CK,len=*),intent(in) :: path !! the path to the variable

call me%core%remove_if_present(me%p,path)

end subroutine json_file_remove
!*****************************************************************************************

!*****************************************************************************************
!>
! Alternate version of [[json_file_remove]], where "path" is kind=CDK.

subroutine wrap_json_file_remove(me,path)

implicit none

class(json_file),intent(inout) :: me
character(kind=CDK,len=*),intent(in) :: path !! the path to the variable

call me%remove(to_unicode(path))

end subroutine wrap_json_file_remove
!*****************************************************************************************

!*****************************************************************************************
end module json_file_module
!*****************************************************************************************
12 changes: 7 additions & 5 deletions src/json_value_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module json_value_module
logical(LK) :: is_verbose = .false. !! if true, all exceptions are
!! immediately printed to console.

logical(LK) :: stop_on_error = .false. !! if true, then the program is
logical(LK) :: stop_on_error = .false. !! if true, then the program is
!! stopped immediately when an
!! exception is raised.

Expand Down Expand Up @@ -6308,8 +6308,9 @@ end subroutine json_get_by_path_default
! are user-specified. To fully conform to the RFC 6901 standard,
! should probably set (via `initialize`):
!
! * `trailing_spaces_significant` = .true. [this is not the default setting]
! * `case_sensitive_keys` = .true. [this is the default setting]
! * `case_sensitive_keys = .true.` [this is the default setting]
! * `trailing_spaces_significant = .true.` [this is *not* the default setting]
! * `allow_duplicate_keys = .false.` [this is *not* the default setting]
!
!### Example
!
Expand Down Expand Up @@ -6454,7 +6455,7 @@ subroutine json_get_by_path_rfc6901(json, me, path, p, found)
end if
if (status_ok) then
! if we make it this far, it should be
! convertable to an integer, so do it.
! convertible to an integer, so do it.
call string_to_integer(token,ival,status_ok)
end if
end if
Expand Down Expand Up @@ -6753,6 +6754,7 @@ subroutine json_get_by_path_jsonpath_bracket(json,me,path,p,found,create_it,was_

! verify that there are no spaces or other
! characters in the string:
status_ok = .true.
do i=1,len(token)
! It must only contain (0..9) characters
! (it must be unsigned)
Expand Down Expand Up @@ -9889,7 +9891,7 @@ subroutine parse_string(json, unit, str, string)
! start accumulating the hex string (should be the next 4 characters)
if (escape) then
escape = .false.
is_hex = (c=='u') !the next four characters are the hex string
is_hex = (c==CK_'u') !the next four characters are the hex string
else
escape = (c==backslash)
end if
Expand Down
16 changes: 12 additions & 4 deletions src/tests/jf_test_01.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ subroutine test_1(error_cnt)
! print the parsed data to the console
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'printing the file...'
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand Down Expand Up @@ -326,9 +326,17 @@ subroutine test_1(error_cnt)
end if
end if

! remove a variable using the remove method:
call json%remove(json_CK_'version.patch')
call json%remove(json_CDK_'version.minor')
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
end if

write(error_unit,'(A)') ''
write(error_unit,'(A)') 'printing the modified structure...'
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand Down Expand Up @@ -362,7 +370,7 @@ subroutine test_1(error_cnt)

write(error_unit,'(A)') ''
write(error_unit,'(A)') 'printing the modified structure...'
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand All @@ -371,7 +379,7 @@ subroutine test_1(error_cnt)
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'printing the modified structure (compact mode)...'
call json%initialize(no_whitespace=.true.)
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand Down
2 changes: 1 addition & 1 deletion src/tests/jf_test_05.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ subroutine test_5(error_cnt)

! print the parsed data to the console:
write(error_unit,'(A)') 'print file...'
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand Down
13 changes: 9 additions & 4 deletions src/tests/jf_test_18.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ subroutine test_18(error_cnt)
integer :: ival
logical :: found
logical,dimension(4) :: ok
integer,dimension(4) :: iresult

write(error_unit,'(A)') ''
write(error_unit,'(A)') '================================='
Expand All @@ -53,19 +54,23 @@ subroutine test_18(error_cnt)

call json%initialize(trailing_spaces_significant=.true.,&
case_sensitive_keys=.true.)
call go([1,2,3,4])
iresult = [1,2,3,4]
call go(iresult)

call json%initialize(trailing_spaces_significant=.false.,&
case_sensitive_keys=.true.)
call go([1,2,1,2])
iresult = [1,2,1,2]
call go(iresult)

call json%initialize(trailing_spaces_significant=.true.,&
case_sensitive_keys=.false.)
call go([1,1,3,3])
iresult = [1,1,3,3]
call go(iresult)

call json%initialize(trailing_spaces_significant=.false.,&
case_sensitive_keys=.false.)
call go([1,1,1,1])
iresult = [1,1,1,1]
call go(iresult)

!cleanup:
call json%destroy(p)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/jf_test_22.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ subroutine test_22(error_cnt)
! print the parsed data to the console
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'printing the file...'
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand Down
2 changes: 1 addition & 1 deletion src/tests/jf_test_23.F90
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ subroutine test_23(error_cnt)
! print the parsed data to the console
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'printing the file...'
call json%print_file()
call json%print_file(error_unit)
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
Expand Down
2 changes: 1 addition & 1 deletion src/tests/jf_test_30.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ subroutine test_30(error_cnt)

call json%initialize(escape_solidus=(i==1), stop_on_error=.true.)
call json%load_from_string(str)
call json%print_file()
call json%print_file(error_unit)

if (json%failed()) then
call json%print_error_message(error_unit)
Expand Down