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, 12 Feb 2024 18:07:18 -0500 (EST)

branch: master
commit b1279b6b9cc36d1e31767899ec05d7d23c99d5aa
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Feb 9 12:13:41 2024 +0100

    * tp/Texinfo/Indices.pm (format_index_entries_sort_strings)
    (setup_sortable_index_entries, _setup_sort_sortable_strings_collator)
    (sort_indices_by_index, sort_indices_by_letter), tp/t/test_sort.t,
    tp/t/test_utils.pl (test): add format_index_entries_sort_strings
    to obtain $index_entries_sort_strings from output of
    setup_index_entries_sort_strings.  Do not output
    $index_entries_sort_strings in setup_sortable_index_entries,
    _setup_sort_sortable_strings_collator, sort_indices_by_index and
    sort_indices_by_letter.  Update callers.
---
 ChangeLog              | 12 +++++++++++
 tp/Texinfo/Document.pm | 10 ++++-----
 tp/Texinfo/Indices.pm  | 58 ++++++++++++++++++++++++++++----------------------
 tp/t/test_sort.t       | 23 ++++++++++++++++----
 tp/t/test_utils.pl     |  9 +++++++-
 5 files changed, 76 insertions(+), 36 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 64ee7bf2d6..b15334975e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -90,6 +90,18 @@
 
        Report from Arnold Robbins.
 
+2024-02-09  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Indices.pm (format_index_entries_sort_strings)
+       (setup_sortable_index_entries, _setup_sort_sortable_strings_collator)
+       (sort_indices_by_index, sort_indices_by_letter), tp/t/test_sort.t,
+       tp/t/test_utils.pl (test): add format_index_entries_sort_strings
+       to obtain $index_entries_sort_strings from output of
+       setup_index_entries_sort_strings.  Do not output
+       $index_entries_sort_strings in setup_sortable_index_entries,
+       _setup_sort_sortable_strings_collator, sort_indices_by_index and
+       sort_indices_by_letter.  Update callers.
+
 2024-02-09  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Document.pm (indices_sort_strings), tp/Texinfo/Indices.pm
diff --git a/tp/Texinfo/Document.pm b/tp/Texinfo/Document.pm
index a7a7763232..69f230a371 100644
--- a/tp/Texinfo/Document.pm
+++ b/tp/Texinfo/Document.pm
@@ -205,6 +205,8 @@ sub merged_indices($)
 }
 
 # TODO document
+# call setup_index_entries_sort_strings and cache the result.
+# TODO XS override
 sub indices_sort_strings($$$;$)
 {
   my $registrar = shift;
@@ -248,9 +250,7 @@ sub sorted_indices_by_letter($$$$$)
     if (!$document->{'sorted_indices_by_letter'});
 
   if (!$document->{'sorted_indices_by_letter'}->{$lang_key}) {
-    my $index_entries_sort_strings;
-    ($document->{'sorted_indices_by_letter'}->{$lang_key},
-     $index_entries_sort_strings)
+    $document->{'sorted_indices_by_letter'}->{$lang_key}
       = Texinfo::Indices::sort_indices_by_letter($registrar,
                                $customization_information,
                         $use_unicode_collation, $locale_lang,
@@ -285,9 +285,7 @@ sub sorted_indices_by_index($$$$$)
     if (!$document->{'sorted_indices_by_index'});
 
   if (!$document->{'sorted_indices_by_index'}->{$lang_key}) {
-    my $index_entries_sort_strings;
-    ($document->{'sorted_indices_by_index'}->{$lang_key},
-     $index_entries_sort_strings)
+    $document->{'sorted_indices_by_index'}->{$lang_key}
       = Texinfo::Indices::sort_indices_by_index($registrar,
                                $customization_information,
                         $use_unicode_collation, $locale_lang,
diff --git a/tp/Texinfo/Indices.pm b/tp/Texinfo/Indices.pm
index 0f31430903..0b34434f25 100644
--- a/tp/Texinfo/Indices.pm
+++ b/tp/Texinfo/Indices.pm
@@ -402,6 +402,24 @@ sub setup_index_entries_sort_strings($$$$;$)
   return $indices_sort_strings;
 }
 
+# TODO document?  Probably not to be called in user-defined code.
+sub format_index_entries_sort_strings($)
+{
+  my $indices_sort_strings = shift;
+  my $index_entries_sort_strings = {};
+
+  return $index_entries_sort_strings unless ($indices_sort_strings);
+
+  foreach my $index_name (keys(%$indices_sort_strings)) {
+    foreach my $index_entry (@{$indices_sort_strings->{$index_name}}) {
+      $index_entries_sort_strings->{$index_entry->{'entry'}}
+         = join(', ', map {$_->{'sort_string'}}
+                          @{$index_entry->{'sort_strings'}});
+    }
+  }
+  return $index_entries_sort_strings;
+}
+
 # There is no strict need for document information in Perl, however, in XS
 # it is needed to retrieve the Tree elements in the C structures.
 # $CUSTOMIZATION_INFORMATION is used as the source of document
@@ -413,12 +431,9 @@ sub setup_sortable_index_entries($$)
   my $collator = shift;
   my $indices_sort_strings = shift;
 
-  my $index_sortable_index_entries;
-  my $index_entries_sort_strings = {};
-  return $index_sortable_index_entries, $index_entries_sort_strings
-    unless ($indices_sort_strings);
+  return undef unless ($indices_sort_strings);
 
-  $index_sortable_index_entries = {};
+  my $index_sortable_index_entries = {};
   foreach my $index_name (keys(%$indices_sort_strings)) {
     my $sortable_index_entries = [];
     foreach my $index_entry (@{$indices_sort_strings->{$index_name}}) {
@@ -442,14 +457,11 @@ sub setup_sortable_index_entries($$)
                             'number' => $index_entry->{'number'},
                             'index_name' => $index_entry->{'index_name'}};
       push @{$sortable_index_entries}, $sortable_entry;
-      $index_entries_sort_strings->{$index_entry->{'entry'}}
-         = join(', ', map {$_->{'sort_string'}}
-                          @{$index_entry->{'sort_strings'}});
     }
     $index_sortable_index_entries->{$index_name} = $sortable_index_entries;
   }
 
-  return ($index_sortable_index_entries, $index_entries_sort_strings);
+  return $index_sortable_index_entries;
 }
 
 sub _setup_sort_sortable_strings_collator($$$$;$$$)
@@ -474,12 +486,10 @@ sub _setup_sort_sortable_strings_collator($$$$;$$$)
 
   my $collator = _setup_collator($use_unicode_collation, $locale_lang);
 
-  my $sorted_index_entries;
-  my ($index_sortable_index_entries, $index_entries_sort_strings)
+  my $index_sortable_index_entries
     = setup_sortable_index_entries($collator, $indices_sort_strings);
 
-  return ($index_sortable_index_entries, $index_entries_sort_strings,
-          $collator);
+  return ($index_sortable_index_entries, $collator);
 }
 
 sub sort_indices_by_index($$$$;$$$)
@@ -492,18 +502,17 @@ sub sort_indices_by_index($$$$;$$$)
   my $indices_information = shift;
   my $document = shift;
 
-  my ($index_sortable_index_entries, $index_entries_sort_strings,
-      $collator) = _setup_sort_sortable_strings_collator($registrar,
+  my ($index_sortable_index_entries, $collator)
+      = _setup_sort_sortable_strings_collator($registrar,
                        $customization_information, $use_unicode_collation,
                        $locale_lang, $index_entries, $indices_information,
                        $document);
 
-  my $sorted_index_entries;
   if (!$index_sortable_index_entries) {
-    return ($sorted_index_entries, $index_entries_sort_strings);
+    return undef;
   }
 
-  $sorted_index_entries = {};
+  my $sorted_index_entries = {};
   foreach my $index_name (keys(%$index_sortable_index_entries)) {
     my $sortable_index_entries = $index_sortable_index_entries->{$index_name};
     $sorted_index_entries->{$index_name} = [
@@ -511,7 +520,7 @@ sub sort_indices_by_index($$$$;$$$)
                                                 @{$sortable_index_entries}
        ];
   }
-  return ($sorted_index_entries, $index_entries_sort_strings);
+  return $sorted_index_entries;
 }
 
 # Return the first non empty text or textual @-command.
@@ -639,18 +648,17 @@ sub sort_indices_by_letter($$$$$$;$)
   my $indices_information = shift;
   my $document = shift;
 
-  my ($index_sortable_index_entries, $index_entries_sort_strings,
-      $collator) = _setup_sort_sortable_strings_collator($registrar,
+  my ($index_sortable_index_entries, $collator)
+     = _setup_sort_sortable_strings_collator($registrar,
                        $customization_information, $use_unicode_collation,
                        $locale_lang, $index_entries, $indices_information,
                        $document);
 
-  my $sorted_index_entries;
   if (!$index_sortable_index_entries) {
-    return ($sorted_index_entries, $index_entries_sort_strings);
+    return undef;
   }
 
-  $sorted_index_entries = {};
+  my $sorted_index_entries = {};
   foreach my $index_name (keys(%$index_sortable_index_entries)) {
     my $sortable_index_entries = $index_sortable_index_entries->{$index_name};
     my $index_letter_hash = {};
@@ -691,7 +699,7 @@ sub sort_indices_by_letter($$$$$$;$)
         { 'letter' => $letter, 'entries' => \@sorted_letter_entries };
     }
   }
-  return ($sorted_index_entries, $index_entries_sort_strings);
+  return $sorted_index_entries;
 }
 
 sub merge_indices($)
diff --git a/tp/t/test_sort.t b/tp/t/test_sort.t
index 18ccd9258f..7bd897c1d0 100644
--- a/tp/t/test_sort.t
+++ b/tp/t/test_sort.t
@@ -51,7 +51,15 @@ my $main_configuration = Texinfo::MainConfig::new({});
 $main_configuration->{'document_descriptor'}
   = $document->document_descriptor();
 #$main_configuration->register_XS_document_main_configuration($document);
-my ($sorted_index_entries, $index_entries_sort_strings)
+
+my $indices_sort_strings
+  = Texinfo::Indices::setup_index_entries_sort_strings($registrar,
+                                              $main_configuration,
+                                          $index_entries, 
$indices_information);
+my $index_entries_sort_strings
+  = Texinfo::Indices::format_index_entries_sort_strings($indices_sort_strings);
+
+my $sorted_index_entries
   = Texinfo::Indices::sort_indices_by_index($registrar, $main_configuration,
                                           undef, undef,
                                           $index_entries, 
$indices_information);
@@ -68,7 +76,7 @@ my @entries_ref = ('!', '"', 'aaaaaaaaaaaa', 'e', 'E', 'ẽ', 
'ł');
 
 cmp_deeply (\@entries, \@entries_ref, 'sorted index entries');
 
-my ($sorted_index_entries_by_letter, $by_letter_index_entries_sort_strings)
+my $sorted_index_entries_by_letter
  = Texinfo::Indices::sort_indices_by_letter($registrar, $main_configuration,
                                           undef, undef,
                                        $index_entries, $indices_information);
@@ -90,7 +98,7 @@ foreach my $letter 
(@{$sorted_index_entries_by_letter->{'cp'}}) {
   push @letter_entries, $letter_entry;
   foreach my $entry (@{$letter->{'entries'}}) {
     push @{$letter_entry->{$letter->{'letter'}}},
-      $by_letter_index_entries_sort_strings->{$entry};
+      $index_entries_sort_strings->{$entry};
   }
 }
 
@@ -130,7 +138,14 @@ $indices_information = $document->indices_information();
 $index_entries = $document->merged_indices();
 $main_configuration->{'document_descriptor'}
   = $document->document_descriptor();
-($sorted_index_entries, $index_entries_sort_strings)
+$indices_sort_strings
+  = Texinfo::Indices::setup_index_entries_sort_strings($registrar,
+                                               $main_configuration,
+                                          $index_entries, 
$indices_information);
+$index_entries_sort_strings
+  = Texinfo::Indices::format_index_entries_sort_strings($indices_sort_strings);
+
+$sorted_index_entries
   = Texinfo::Indices::sort_indices_by_index($registrar, $main_configuration,
                                           undef, undef,
                                           $index_entries, 
$indices_information);
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index b07797c720..5d828b39ae 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1187,7 +1187,14 @@ sub test($$)
        = $main_configuration->get_conf('COLLATION_LANGUAGE');
     }
 
-    ($sorted_index_entries, $index_entries_sort_strings)
+    my $indices_sort_strings
+      = Texinfo::Document::indices_sort_strings($registrar,
+                                   $main_configuration, $document);
+    $index_entries_sort_strings
+     = Texinfo::Indices::format_index_entries_sort_strings(
+                                                     $indices_sort_strings);
+
+    $sorted_index_entries
       = Texinfo::Indices::sort_indices_by_index($registrar,
                                                 $main_configuration,
                                  $use_unicode_collation, $locale_lang,



reply via email to

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