]> git.donarmstrong.com Git - lilypond.git/commitdiff
texi2html: make filename generation more efficient/easier to understand
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 20 Jul 2008 23:52:16 +0000 (01:52 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 20 Jul 2008 23:52:16 +0000 (01:52 +0200)
lilypond-texi2html.init

index bddf286bcb7b9d75b8bed0aba1173ce15bb267dc..a6e52d32bbf032c22169dafd23a8c08e23f9300a 100644 (file)
@@ -113,38 +113,31 @@ sub print_element_info($)
 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
 sub texinfo_file_name($)
 {
-  my $str = shift;
+  my $text = shift;
+  my $result = '';
   # File name normalization by texinfo:
   # 1/2: letters and numbers are left unchanged
   # 3/4: multiple, leading and trailing whitespace is removed
-  $str = main::normalise_space($str);
+  $text = main::normalise_space($text);
   # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
   #      chars are replaced by _xxxx (xxxx=ascii character code)
-  my @chars = split(//, $str);
-  my $str = '';
-  foreach my $char (@chars) {
-    if ( $char eq ' ' ) { # space -> '-'
-      $str .= '-';
-    } elsif ( ('0' le $char and $char le '9' ) or
-              ('A' le $char and $char le 'Z' ) or
-              ('a' le $char and $char le 'z' ) ) { # number or letter
-      $str .= $char;
-    } else {
-      my $ccode = ord($char);
-      my $addstr;
-      if ( ord($char)<= 0xFFFF ) {
-        $addstr = sprintf("_%4x", $ccode);
+  while ($text ne '') {
+    if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
+      $result .= $1;
+    } elsif ($text =~ s/^ //o) { # space -> '-'
+      $result .= '-';
+    } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
+      my $ccode = ord($1);
+      if ( $ccode <= 0xFFFF ) {
+        $result .= sprintf("_%04x", $ccode);
       } else {
-        $addstr = sprintf("__%6x", $ccode);
+        $result .= sprintf("__%06x", $ccode);
       }
-      # padding is done by spaces, replace by '0'
-      $addstr =~ s/\ /0/g;
-      $str .= $addstr;
     }
   }
   # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
-  if ($str !~ /^[a-zA-Z]/) {
-    $str = 't_g' . $str;
+  if ($result !~ /^[a-zA-Z]/) {
+    $result = 't_g' . $str;
   }
   # DONE
   return $str