[gtranslator] Rework the plural forms parsing. Fixes bug #609115.



commit eea4018cef5364f74459c3a8446c7cb877ed09d0
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat Feb 6 22:04:58 2010 +0100

    Rework the plural forms parsing. Fixes bug #609115.

 src/gtr-header.c |   41 +++++++++++++++++++++++++++--------------
 1 files changed, 27 insertions(+), 14 deletions(-)
---
diff --git a/src/gtr-header.c b/src/gtr-header.c
index 523dff6..d81caf2 100644
--- a/src/gtr-header.c
+++ b/src/gtr-header.c
@@ -67,40 +67,53 @@ parse_nplurals (GtrHeader * header)
 {
   gchar *pointer, *plural_forms;
 
-  plural_forms = g_strdup (gtranslator_header_get_plural_forms (header));
+  plural_forms = gtranslator_header_get_plural_forms (header);
+  header->priv->nplurals = -1;
 
-  if (!plural_forms)
+  if (gtranslator_prefs_manager_get_use_profile_values () || !plural_forms)
     {
       const gchar *plural_form;
       GtrProfile *profile;
 
-      header->priv->nplurals = -1;
-
       profile = gtranslator_application_get_active_profile (GTR_APP);
 
       if (profile)
         plural_form = gtranslator_profile_get_plurals (profile);
-      else
+      else if (!plural_forms)
         return;
 
       if (plural_form)
         {
-          gtranslator_header_set_plural_forms (header, plural_form);
+          g_free (plural_forms);
           plural_forms = g_strdup (plural_form);
         }
+      else if (!plural_forms)
+        return;
     }
 
-  pointer = plural_forms;
+  pointer = g_strrstr (plural_forms, "nplurals");
+
+  if (pointer != NULL)
+    {
+      while (*pointer != '\0' && *pointer != '=')
+        pointer++;
+
+      if (pointer != '\0')
+        {
+          pointer++;
+          while (*pointer != '\0' && *pointer == ' ')
+            pointer++;
 
-  while (*pointer != '\0' && *pointer != '=')
-    pointer++;
-  pointer++;
+          if (*pointer == '\0')
+            return;
+        }
+      else
+        return;
 
-  //if there are any space between '=' and nplural number pointer++
-  while (*pointer != '\0' && *pointer == ' ')
-    pointer++;
+      header->priv->nplurals = g_ascii_digit_value (*pointer);
+    }
 
-  header->priv->nplurals = g_ascii_digit_value (*pointer);
+  /*g_message ("nplurals: %d", header->priv->nplurals);*/
 
   g_free (plural_forms);
 }



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