@@ -148,7 +148,6 @@ module json_value_module
148
148
! call json%print(p,'test.json') !write it to a file
149
149
! call json%destroy(p) !cleanup
150
150
! end program test
151
- ! type,public :: json_core
152
151
! ````
153
152
type,public :: json_core
154
153
@@ -503,6 +502,14 @@ module json_value_module
503
502
procedure :: json_matrix_info
504
503
procedure :: MAYBEWRAP(json_matrix_info_by_path)
505
504
505
+ ! >
506
+ ! insert a new element after an existing one,
507
+ ! updating the JSON structure accordingly
508
+ generic,public :: insert_after = > json_value_insert_after, &
509
+ json_value_insert_after_child_by_index
510
+ procedure :: json_value_insert_after
511
+ procedure :: json_value_insert_after_child_by_index
512
+
506
513
procedure ,public :: remove = > json_value_remove ! ! Remove a [[json_value]] from a linked-list structure.
507
514
procedure ,public :: check_for_errors = > json_check_for_errors ! ! check for error and get error message
508
515
procedure ,public :: clear_exceptions = > json_clear_exceptions ! ! clear exceptions
@@ -522,8 +529,6 @@ module json_value_module
522
529
procedure ,public :: validate = > json_value_validate ! ! Check that a [[json_value]] linked list is valid
523
530
! ! (i.e., is properly constructed). This may be
524
531
! ! useful if it has been constructed externally.
525
- procedure ,public :: insert_after = > json_value_insert_after ! ! insert a new element after an existing one,
526
- ! ! updating the JSON structure accordingly
527
532
528
533
! other private routines:
529
534
procedure :: name_equal
@@ -2485,7 +2490,7 @@ end subroutine json_value_add_member
2485
2490
2486
2491
! *****************************************************************************************
2487
2492
! >
2488
- ! Inserts `new ` after `p`, and updates the JSON structure accordingly.
2493
+ ! Inserts `element ` after `p`, and updates the JSON structure accordingly.
2489
2494
!
2490
2495
! ### Example
2491
2496
!
@@ -2533,7 +2538,7 @@ subroutine json_value_insert_after(json,p,element)
2533
2538
element% parent = > null ()
2534
2539
end if
2535
2540
2536
- ! if are there any in the list after p:
2541
+ ! if there are any in the list after p:
2537
2542
if (associated (p% next)) then
2538
2543
element% next = > p% next
2539
2544
element% next% previous = > element
@@ -2549,6 +2554,37 @@ subroutine json_value_insert_after(json,p,element)
2549
2554
end subroutine json_value_insert_after
2550
2555
! *****************************************************************************************
2551
2556
2557
+ ! *****************************************************************************************
2558
+ ! >
2559
+ ! Inserts `element` after the `idx`-th child of `p`,
2560
+ ! and updates the JSON structure accordingly. It is just
2561
+ ! a wrapper for [[json_value_insert_after]].
2562
+
2563
+ subroutine json_value_insert_after_child_by_index (json ,p ,idx ,element )
2564
+
2565
+ implicit none
2566
+
2567
+ class(json_core),intent (inout ) :: json
2568
+ type (json_value),pointer :: p ! ! a JSON object or array.
2569
+ integer (IK),intent (in ) :: idx ! ! the index of the child of `p` to
2570
+ ! ! insert the new element after
2571
+ type (json_value),pointer :: element ! ! the element to insert
2572
+
2573
+ type (json_value),pointer :: tmp ! ! for getting the `idx`-th child of `p`
2574
+
2575
+ if (.not. json% exception_thrown) then
2576
+
2577
+ ! get the idx-th child of p:
2578
+ call json% get_child(p,idx,tmp)
2579
+
2580
+ ! call json_value_insert_after:
2581
+ if (.not. json% failed()) call json% insert_after(tmp,element)
2582
+
2583
+ end if
2584
+
2585
+ end subroutine json_value_insert_after_child_by_index
2586
+ ! *****************************************************************************************
2587
+
2552
2588
! *****************************************************************************************
2553
2589
! > author: Jacob Williams
2554
2590
! date: 1/19/2014
0 commit comments