texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp/Texinfo Common.pm Convert/Plaintext....


From: Patrice Dumas
Subject: texinfo/tp/Texinfo Common.pm Convert/Plaintext....
Date: Wed, 28 Sep 2011 23:02:57 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/09/28 23:02:57

Modified files:
        tp/Texinfo     : Common.pm 
        tp/Texinfo/Convert: Plaintext.pm Text.pm 

Log message:
        Move enumerate_item_representation from Texinfo::Convert::Text to
        Texinfo::Common.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.162&r2=1.163
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Text.pm?cvsroot=texinfo&r1=1.57&r2=1.58

Patches:
Index: Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- Common.pm   28 Sep 2011 06:53:38 -0000      1.63
+++ Common.pm   28 Sep 2011 23:02:56 -0000      1.64
@@ -1001,6 +1001,50 @@
   return ($caption, $prepended);
 }
 
+# decompose a decimal number on a given base. The algorithm looks like
+# the division with growing powers (division suivant les puissances
+# croissantes) ?
+sub _decompose_integer($$)
+{
+  my $number = shift;
+  my $base = shift;
+  my @result = ();
+
+  return (0) if ($number == 0);
+  my $power = 1;
+  my $remaining = $number;
+
+  while ($remaining) {
+    my $factor = $remaining % ($base ** $power);
+    $remaining -= $factor;
+    push (@result, $factor / ($base ** ($power - 1)));
+    $power++;
+  }
+  return @result;
+}
+
+sub enumerate_item_representation($$)
+{
+  my $specification = shift;
+  my $number = shift;
+
+  if ($specification =~ /^[0-9]$/) {
+    return $specification + $number -1;
+  }
+
+  my $result = '';
+  my $base_letter = ord('a');
+  $base_letter = ord('A') if (ucfirst($specification) eq $specification);
+  my @letter_ords = _decompose_integer(ord($specification) - $base_letter + 
$number - 1, 26);
+  foreach my $ord (@letter_ords) {
+    # FIXME we go directly to 'ba' after 'z', and not 'aa'
+    #because 'ba' is 1,0 and 'aa' is 0,0.
+    $result = chr($base_letter + $ord) . $result;
+  }
+  return $result;
+}
+
+
 our %htmlxref_entries = (
  'node' => [ 'node', 'section', 'chapter', 'mono' ],
  'section' => [ 'section', 'chapter','node', 'mono' ],
@@ -1334,11 +1378,6 @@
 returns a texinfo tree corresponding to the category of the
 I<$def_line> taking the class into account, if there is one.
 
-=item trim_spaces_comment_from_content($contents)
-
-Remove empty spaces after commands or braces at begina and
-and spaces and comments at end from a content array, modifying it.
-
 =item ($caption, $prepended) = float_name_caption ($converter, $float)
 
 I<$float> is a texinfo tree C<@float> element.  This function 
@@ -1346,6 +1385,21 @@
 and the I<$prepended> texinfo tree combining the type and label
 of the float.
 
+=item $text = enumerate_item_representation($specification, $number)
+
+This function returns the number or letter correponding to item
+number I<$number> for an C<@enumerate> specification I<$specification>,
+appearing on an C<@enumerate> line.  For example
+
+  enumerate_item_representation('c', 3)
+
+is C<e>.
+
+=item trim_spaces_comment_from_content($contents)
+
+Remove empty spaces after commands or braces at begina and
+and spaces and comments at end from a content array, modifying it.
+
 =item $normalized_name = normalize_top_node_name ($node_string)
 
 Normalize the node name string given in argument, by normalizing

Index: Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -b -r1.162 -r1.163
--- Convert/Plaintext.pm        27 Sep 2011 23:44:09 -0000      1.162
+++ Convert/Plaintext.pm        28 Sep 2011 23:02:57 -0000      1.163
@@ -1792,7 +1792,7 @@
       if ($root->{'parent'}->{'cmdname'} eq 'enumerate') {
         $result = $self->_count_added($line->{'container'},
             $line->{'container'}->add_next(
-               Texinfo::Convert::Text::enumerate_item_representation(
+               Texinfo::Common::enumerate_item_representation(
                  $root->{'parent'}->{'extra'}->{'enumerate_specification'},
                  $root->{'extra'}->{'item_number'}) . '. '));
       } elsif ($root->{'parent'}->{'extra'}->{'block_command_line_contents'}) {

Index: Convert/Text.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Text.pm,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- Convert/Text.pm     4 Sep 2011 18:13:16 -0000       1.57
+++ Convert/Text.pm     28 Sep 2011 23:02:57 -0000      1.58
@@ -873,50 +873,6 @@
   return $result;
 }
 
-# decompose a decimal number on a given base. The algorithm looks like
-# the division with growing powers (division suivant les puissances
-# croissantes) ?
-sub _decompose_integer($$)
-{
-  my $number = shift;
-  my $base = shift;
-  my @result = ();
-
-  return (0) if ($number == 0);
-  my $power = 1;
-  my $remaining = $number;
-
-  while ($remaining) {
-    my $factor = $remaining % ($base ** $power);
-    $remaining -= $factor;
-    push (@result, $factor / ($base ** ($power - 1)));
-    $power++;
-  }
-  return @result;
-}
-
-# the enumerate item number or letter.
-sub enumerate_item_representation($$)
-{
-  my $specification = shift;
-  my $number = shift;
-
-  if ($specification =~ /^[0-9]$/) {
-    return $specification + $number -1;
-  }
-
-  my $result = '';
-  my $base_letter = ord('a');
-  $base_letter = ord('A') if (ucfirst($specification) eq $specification);
-  my @letter_ords = _decompose_integer(ord($specification) - $base_letter + 
$number - 1, 26);
-  foreach my $ord (@letter_ords) {
-    # FIXME we go directly to 'ba' after 'z', and not 'aa'
-    #because 'ba' is 1,0 and 'aa' is 0,0.
-    $result = chr($base_letter + $ord) . $result;
-  }
-  return $result;
-}
-
 my %underline_symbol = (
   0 => '*',
   1 => '*',
@@ -1135,7 +1091,7 @@
     } elsif ($root->{'cmdname'} eq 'item' 
             and $root->{'parent'}->{'cmdname'} 
             and $root->{'parent'}->{'cmdname'} eq 'enumerate') {
-      $result .= enumerate_item_representation(
+      $result .= Texinfo::Common::enumerate_item_representation(
          $root->{'parent'}->{'extra'}->{'enumerate_specification'},
          $root->{'extra'}->{'item_number'}) . '. ';
     }



reply via email to

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