@@ -278,21 +278,21 @@ module json_value_module
278278 json_value_add_string_vec_val_ascii
279279#endif
280280
281- procedure ,private :: json_value_add_member
282- procedure ,private :: MAYBEWRAP(json_value_add_integer)
283- procedure ,private :: MAYBEWRAP(json_value_add_null)
284- procedure ,private :: MAYBEWRAP(json_value_add_integer_vec)
285- procedure ,private :: MAYBEWRAP(json_value_add_double)
286- procedure ,private :: MAYBEWRAP(json_value_add_double_vec)
287- procedure ,private :: MAYBEWRAP(json_value_add_logical)
288- procedure ,private :: MAYBEWRAP(json_value_add_logical_vec)
289- procedure ,private :: MAYBEWRAP(json_value_add_string)
290- procedure ,private :: MAYBEWRAP(json_value_add_string_vec)
281+ procedure ,private :: json_value_add_member
282+ procedure ,private :: MAYBEWRAP(json_value_add_integer)
283+ procedure ,private :: MAYBEWRAP(json_value_add_null)
284+ procedure ,private :: MAYBEWRAP(json_value_add_integer_vec)
285+ procedure ,private :: MAYBEWRAP(json_value_add_double)
286+ procedure ,private :: MAYBEWRAP(json_value_add_double_vec)
287+ procedure ,private :: MAYBEWRAP(json_value_add_logical)
288+ procedure ,private :: MAYBEWRAP(json_value_add_logical_vec)
289+ procedure ,private :: MAYBEWRAP(json_value_add_string)
290+ procedure ,private :: MAYBEWRAP(json_value_add_string_vec)
291291#ifdef USE_UCS4
292- procedure ,private :: json_value_add_string_name_ascii
293- procedure ,private :: json_value_add_string_val_ascii
294- procedure ,private :: json_value_add_string_vec_name_ascii
295- procedure ,private :: json_value_add_string_vec_val_ascii
292+ procedure ,private :: json_value_add_string_name_ascii
293+ procedure ,private :: json_value_add_string_val_ascii
294+ procedure ,private :: json_value_add_string_vec_name_ascii
295+ procedure ,private :: json_value_add_string_vec_val_ascii
296296#endif
297297
298298 ! >
@@ -386,6 +386,17 @@ module json_value_module
386386 procedure :: json_add_string_vec_by_path_path_ascii
387387#endif
388388
389+ ! >
390+ ! Rename a variable, by specifying its path.
391+ generic,public :: rename_by_path = > MAYBEWRAP(json_rename_by_path)
392+ procedure :: MAYBEWRAP(json_rename_by_path)
393+ #ifdef USE_UCS4
394+ generic,public :: rename_by_path = > json_rename_by_path_name_ascii,&
395+ json_rename_by_path_path_ascii
396+ procedure :: json_rename_by_path_name_ascii
397+ procedure :: json_rename_by_path_path_ascii
398+ #endif
399+
389400 ! >
390401 ! Create a [[json_value]] linked list using the
391402 ! path to the variables. Optionally return a
@@ -5678,6 +5689,107 @@ subroutine wrap_json_create_by_path(json,me,path,p,found,was_created)
56785689 end subroutine wrap_json_create_by_path
56795690! *****************************************************************************************
56805691
5692+ ! *****************************************************************************************
5693+ ! >
5694+ ! Rename a [[json_value]], given the path.
5695+
5696+ subroutine json_rename_by_path (json , me , path , name , found )
5697+
5698+ implicit none
5699+
5700+ class(json_core),intent (inout ) :: json
5701+ type (json_value),pointer ,intent (in ) :: me
5702+ character (kind= CK,len=* ),intent (in ) :: path
5703+ character (kind= CK,len=* ),intent (in ) :: name ! ! the new name
5704+ logical (LK),intent (out ),optional :: found
5705+
5706+ type (json_value),pointer :: p
5707+
5708+ if ( json% exception_thrown ) then
5709+ if ( present (found) ) found = .false.
5710+ return
5711+ end if
5712+
5713+ nullify(p)
5714+ call json% get(me= me, path= path, p= p)
5715+
5716+ if (.not. associated (p)) then
5717+ call json% throw_exception(' Error in json_rename_by_path:' // &
5718+ ' Unable to resolve path: ' // trim (path))
5719+ else
5720+ call json% rename(p,name)
5721+ nullify(p)
5722+ end if
5723+
5724+ if (json% exception_thrown) then
5725+ if (present (found)) then
5726+ found = .false.
5727+ call json% clear_exceptions()
5728+ end if
5729+ else
5730+ if (present (found)) found = .true.
5731+ end if
5732+
5733+ end subroutine json_rename_by_path
5734+ ! *****************************************************************************************
5735+
5736+ ! *****************************************************************************************
5737+ ! >
5738+ ! Alternate version of [[json_rename_by_path]], where "path" and "name" are kind=CDK
5739+
5740+ subroutine wrap_json_rename_by_path (json , me , path , name , found )
5741+
5742+ implicit none
5743+
5744+ class(json_core),intent (inout ) :: json
5745+ type (json_value),pointer ,intent (in ) :: me
5746+ character (kind= CDK,len=* ),intent (in ) :: path
5747+ character (kind= CDK,len=* ),intent (in ) :: name
5748+ logical (LK),intent (out ),optional :: found
5749+
5750+ call json% rename_by_path(me,to_unicode(path),to_unicode(name),found)
5751+
5752+ end subroutine wrap_json_rename_by_path
5753+ ! *****************************************************************************************
5754+
5755+ ! *****************************************************************************************
5756+ ! >
5757+ ! Alternate version of [[json_rename_by_path]], where "name" is kind=CDK
5758+
5759+ subroutine wrap_json_rename_by_path_name_ascii (json , me , path , name , found )
5760+
5761+ implicit none
5762+
5763+ class(json_core),intent (inout ) :: json
5764+ type (json_value),pointer ,intent (in ) :: me
5765+ character (kind= CK,len=* ),intent (in ) :: path
5766+ character (kind= CDK,len=* ),intent (in ) :: name
5767+ logical (LK),intent (out ),optional :: found
5768+
5769+ call json% rename_by_path(me,path,to_unicode(name),found)
5770+
5771+ end subroutine wrap_json_rename_by_path_name_ascii
5772+ ! *****************************************************************************************
5773+
5774+ ! *****************************************************************************************
5775+ ! >
5776+ ! Alternate version of [[json_rename_by_path]], where "path" is kind=CDK
5777+
5778+ subroutine json_rename_by_path_path_ascii (json , me , path , name , found )
5779+
5780+ implicit none
5781+
5782+ class(json_core),intent (inout ) :: json
5783+ type (json_value),pointer ,intent (in ) :: me
5784+ character (kind= CDK,len=* ),intent (in ) :: path
5785+ character (kind= CK,len=* ),intent (in ) :: name
5786+ logical (LK),intent (out ),optional :: found
5787+
5788+ call json% rename_by_path(me,to_unicode(path),name,found)
5789+
5790+ end subroutine json_rename_by_path_path_ascii
5791+ ! *****************************************************************************************
5792+
56815793! *****************************************************************************************
56825794! >
56835795! Returns the [[json_value]] pointer given the path string.
0 commit comments