[Libreoffice-commits] .: Branch 'libreoffice-3-3' - 2 commits - solenv/bin

Fridrich Strba fridrich at kemper.freedesktop.org
Fri Dec 17 12:58:18 PST 2010


 solenv/bin/modules/pre2par/language.pm |  107 ++++++++++++---------------------
 1 file changed, 41 insertions(+), 66 deletions(-)

New commits:
commit 62e1be8d60c4e44aec7a7f92f6e249873171f223
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Dec 17 20:27:35 2010 +0000

    another 4x faster - down to ~2 seconds now for me.

diff --git a/solenv/bin/modules/pre2par/language.pm b/solenv/bin/modules/pre2par/language.pm
index bc02064..56162a8 100644
--- a/solenv/bin/modules/pre2par/language.pm
+++ b/solenv/bin/modules/pre2par/language.pm
@@ -27,6 +27,7 @@
 
 package pre2par::language;
 
+use strict;
 use pre2par::existence;
 
 ##############################################################
@@ -71,39 +72,6 @@ sub get_language_string_from_language_block
     return $newstring;
 }
 
-##############################################################
-# Returning the complete block in all languages
-# for a specified string
-##############################################################
-
-sub get_language_block_from_language_file
-{
-    my ($searchstring, $langfile) = @_;
-
-    my @language_block = ();
-
-    for ( my $i = 0; $i <= $#{$langfile}; $i++ )
-    {		
-        if ( ${$langfile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
-        {
-            my $counter = $i;
-
-            push(@language_block, ${$langfile}[$counter]);
-            $counter++;
-            
-            while (( $counter <= $#{$langfile} ) && (!( ${$langfile}[$counter] =~ /^\s*\[/ )))
-            {
-                push(@language_block, ${$langfile}[$counter]);
-                $counter++;
-            }
-            
-            last;
-        }
-    }	
-    
-    return \@language_block;
-}
-
 ############################################
 # collecting all replace variables
 # in a language file
@@ -119,7 +87,20 @@ sub get_all_replace_variables
     {
         if ( ${$langfile}[$i] =~ /^\s*\[\s*(.*?)\s*\]\s*$/ )
         {
-	    $allvars{$1} = 1;
+	    my $variable = $1;
+#	    print "lang block '$variable'\n";
+	    my @lang_block = ();
+	    my $counter;
+
+	    # Store the complete block in all languages for a specified variable
+            for ( $counter = $i + 1; $counter <= $#{$langfile}; $counter++ ) {
+		my $line = ${$langfile}[$counter];
+		last if ($line =~ /^s*\[/); # next decl.
+		push @lang_block, $line;
+	    }
+#	    print "$variable = '@lang_block'\n";
+	    $allvars{$variable} = \@lang_block;
+	    $i = $counter - 1;
         }
     }
 
@@ -151,9 +132,8 @@ sub localize
 #	    print "line '$oneline' split to '$language' '$variable'\n";
 
 	    if (defined $replace_hash->{$variable}) {
-                    my $languageblock = get_language_block_from_language_file($variable, $langfile);
-                    my $newstring = get_language_string_from_language_block($languageblock, $language);
-
+                    my $languageblock = $replace_hash->{$variable};
+                    my $newstring = get_language_string_from_language_block($replace_hash->{$variable}, $language);
                     if ( $newstring eq "" )	{ $newstring = "\"" . $variable . "\""; }
 
                     $oneline =~ s/$variable/$newstring/g;
commit 319866daf1d2eb51947db03e04bea388b181745c
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Dec 17 20:04:29 2010 +0000

    make pre2par 5x faster, and simpler too

diff --git a/solenv/bin/modules/pre2par/language.pm b/solenv/bin/modules/pre2par/language.pm
index 62d96f9..bc02064 100644
--- a/solenv/bin/modules/pre2par/language.pm
+++ b/solenv/bin/modules/pre2par/language.pm
@@ -105,29 +105,25 @@ sub get_language_block_from_language_file
 }
 
 ############################################
-# collecting all replace strings
+# collecting all replace variables
 # in a language file
 ############################################
 
-sub get_all_replace_strings
+sub get_all_replace_variables
 {
     my ($langfile) = @_;
 
-    my @allstrings = ();
-    
+    my %allvars = ();
+
     for ( my $i = 0; $i <= $#{$langfile}; $i++ )
-    {		
+    {
         if ( ${$langfile}[$i] =~ /^\s*\[\s*(.*?)\s*\]\s*$/ )
         {
-            my $replacestring = $1;
-            if (! pre2par::existence::exists_in_array($replacestring, \@allstrings))
-            {
-                push(@allstrings, $replacestring);
-            }
+	    $allvars{$1} = 1;
         }
     }
-    
-    return \@allstrings;
+
+    return \%allvars;
 }
 
 ############################################
@@ -139,34 +135,33 @@ sub localize
 {
     my ($parfile, $langfile) = @_;
 
-    my $allreplacestrings = get_all_replace_strings($langfile);	
-    
+    my $replace_hash = get_all_replace_variables($langfile);
+
+    # parse lines of the form Name (st) = STR_NAME_MODULE_HELPPACK_OC;
+    # for variable substitution
+    my $langlinere = qr/^\s*\w+\s*\(([\w-]+)\)\s*\=\s*([\w-]+)\s*;/;
     for ( my $i = 0; $i <= $#{$parfile}; $i++ )
     {
         my $oneline = ${$parfile}[$i];
 
-        for ( my $j = 0; $j <= $#{$allreplacestrings}; $j++ )
-        {
-            if ( $oneline =~ /\b${$allreplacestrings}[$j]\b/ ) # Not for basic scripts
-            {
-                my $oldstring = ${$allreplacestrings}[$j];
-                
-                if ( $oneline =~ /^\s*\w+\s*\(([\w-]+)\)\s*\=/ )
-                {
-                    my $language = $1; 	 # can be "01" or "en" or "en-US" or ...
-                    
-                    my $languageblock = get_language_block_from_language_file($oldstring, $langfile);
+	if ( $oneline =~ $langlinere) {
+	    my $language = $1; 	 # can be "01" or "en" or "en-US" or ...
+	    my $variable = $2;
+
+#	    print "line '$oneline' split to '$language' '$variable'\n";
+
+	    if (defined $replace_hash->{$variable}) {
+                    my $languageblock = get_language_block_from_language_file($variable, $langfile);
                     my $newstring = get_language_string_from_language_block($languageblock, $language);
 
-                    if ( $newstring eq "" )	{ $newstring = "\"" . $oldstring . "\""; }
-                    
-                    $oneline =~ s/$oldstring/$newstring/g;
-                        
+                    if ( $newstring eq "" )	{ $newstring = "\"" . $variable . "\""; }
+
+                    $oneline =~ s/$variable/$newstring/g;
+
                     ${$parfile}[$i] = $oneline;
                 }
-            }
         }
-    }	
+    }
 }
 
 1;


More information about the Libreoffice-commits mailing list