Skip to content

Commit f10d085

Browse files
committed
added remove() method to json_file. Fixes #339
1 parent 8022459 commit f10d085

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/json_file_module.F90

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ module json_file_module
169169
json_file_update_string_val_ascii
170170
#endif
171171

172+
!>
173+
! Remove a variable from a [[json_file(type)]]
174+
! by specifying the path.
175+
generic,public :: remove => MAYBEWRAP(json_file_remove)
176+
172177
!traverse
173178
procedure,public :: traverse => json_file_traverse
174179

@@ -244,6 +249,9 @@ module json_file_module
244249
procedure :: json_file_update_string_val_ascii
245250
#endif
246251

252+
!remove:
253+
procedure :: MAYBEWRAP(json_file_remove)
254+
247255
!print_file:
248256
procedure :: json_file_print_to_console
249257
procedure :: json_file_print_1
@@ -2192,6 +2200,42 @@ subroutine json_file_traverse(me,traverse_callback)
21922200
end subroutine json_file_traverse
21932201
!*****************************************************************************************
21942202

2203+
!*****************************************************************************************
2204+
!> author: Jacob Williams
2205+
! date: 7/7/2018
2206+
!
2207+
! Remove a variable from a JSON file.
2208+
!
2209+
!@note This is just a wrapper to [[remove_if_present]].
2210+
2211+
subroutine json_file_remove(me,path)
2212+
2213+
implicit none
2214+
2215+
class(json_file),intent(inout) :: me
2216+
character(kind=CK,len=*),intent(in) :: path !! the path to the variable
2217+
2218+
call me%core%remove_if_present(me%p,path)
2219+
2220+
end subroutine json_file_remove
2221+
!*****************************************************************************************
2222+
2223+
!*****************************************************************************************
2224+
!>
2225+
! Alternate version of [[json_file_remove]], where "path" is kind=CDK.
2226+
2227+
subroutine wrap_json_file_remove(me,path)
2228+
2229+
implicit none
2230+
2231+
class(json_file),intent(inout) :: me
2232+
character(kind=CDK,len=*),intent(in) :: path !! the path to the variable
2233+
2234+
call me%remove(to_unicode(path))
2235+
2236+
end subroutine wrap_json_file_remove
2237+
!*****************************************************************************************
2238+
21952239
!*****************************************************************************************
21962240
end module json_file_module
21972241
!*****************************************************************************************

src/tests/jf_test_01.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ subroutine test_1(error_cnt)
326326
end if
327327
end if
328328

329+
! remove a variable using the remove method:
330+
call json%remove(json_CK_'version.patch')
331+
call json%remove(json_CDK_'version.minor')
332+
if (json%failed()) then
333+
call json%print_error_message(error_unit)
334+
error_cnt = error_cnt + 1
335+
end if
336+
329337
write(error_unit,'(A)') ''
330338
write(error_unit,'(A)') 'printing the modified structure...'
331339
call json%print_file()

0 commit comments

Comments
 (0)