texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Mon, 15 Apr 2024 16:46:36 -0400 (EDT)

branch: master
commit 8f0194bb7c09c14bcc85c6251683a2cb9555ddee
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Apr 15 22:10:55 2024 +0200

    * tp/Texinfo/Common.pm (remove_from_array): add a simple function to
    remove the first occurence of an element in an array.
    
    * tp/Texinfo/Transformations.pm (regenerate_master_menu): use
    Texinfo::Common remove_from_array to remove the removed menu entries
    from the internal references list.
---
 ChangeLog                     |  9 +++++++++
 tp/Texinfo/Common.pm          | 20 ++++++++++++++++++++
 tp/Texinfo/Transformations.pm | 14 ++------------
 3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 79d8817699..7a22acbbdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-04-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (remove_from_array): add a simple function to
+       remove the first occurence of an element in an array.
+
+       * tp/Texinfo/Transformations.pm (regenerate_master_menu): use
+       Texinfo::Common remove_from_array to remove the removed menu entries
+       from the internal references list.
+
 2024-04-15  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Makefile.tres, tp/t/transformations.t
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 528dcdd733..fc7252c770 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1393,6 +1393,21 @@ sub lookup_index_entry($$)
   return (undef, $index_info);
 }
 
+# only used from Perl
+# Remove first $ELEMENT from $ARRAY
+sub remove_from_array($$)
+{
+  my $array = shift;
+  my $element = shift;
+
+  for (my $index = 0; $index < scalar(@$array); $index++) {
+    if ($array->[$index] eq $element) {
+      return splice(@$array, $index, 1);
+    }
+  }
+  return undef;
+}
+
 sub set_output_encodings($$)
 {
   my $customization_information = shift;
@@ -2320,6 +2335,11 @@ X<C<normalize_top_node_name>>
 Normalize the node name string given in argument, by normalizing
 Top node case.
 
+=item $result = remove_from_array($array, $element)
+
+Remove first occurence of I<$element> in the array reference I<$array>.
+Return the removed element, or C<undef> if not found.
+
 =item $level = section_level($section)
 X<C<section_level>>
 
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index 44558ac4cf..c4f106b549 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -692,18 +692,8 @@ sub regenerate_master_menu($;$)
             foreach my $entry_content (@{$detailmenu_entry->{'contents'}}) {
               if ($entry_content->{'type'}
                   and $entry_content->{'type'} eq 'menu_entry_node') {
-                my $index = 0;
-                my $internal_references_idx = -1;
-                foreach my $internal_ref (@$internal_references) {
-                  if ($internal_ref eq $entry_content) {
-                    $internal_references_idx = $index;
-                    last;
-                  }
-                  $index++;
-                }
-                if ($internal_references_idx >= 0) {
-                  splice (@$internal_references, $internal_references_idx, 1);
-                }
+                Texinfo::Common::remove_from_array($internal_references,
+                                                   $entry_content);
               }
             }
           }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]