]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
When sorting, disambiguate when the msgids are the same.
authorBruno Haible <bruno@clisp.org>
Fri, 26 Sep 2008 15:59:35 +0000 (15:59 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:51 +0000 (12:15 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/write-catalog.c

index b380d2f143174f56856e4150045df7749428c29c..399b9caf11120055cfb52ac4ea311c80f00a08a0 100644 (file)
@@ -1,9 +1,15 @@
-2009-09-15  Bruno Haible  <bruno@clisp.org>
+2008-09-26  Bruno Haible  <bruno@clisp.org>
+
+       * write-catalog.c (cmp_by_msgid, cmp_by_filepos): Compare the msgctxt
+       fields if the msgid fields are the same.
+       Reported by Rainer Tammer <tammer@tammer.net>.
+
+2008-09-15  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (msg*_DEPENDENCIES, xgettext_DEPENDENCIES,
        recode_sr_latin_DEPENDENCIES): New variables.
 
-2009-09-15  Bruno Haible  <bruno@clisp.org>
+2008-09-15  Bruno Haible  <bruno@clisp.org>
 
        * msgl-fsearch.h: Include stdbool.h.
        (message_fuzzy_index_search): Add 'heuristic' argument.
@@ -27,7 +33,7 @@
        for a lazily allocated hashed index.
        * Makefile.am (msgcmp_SOURCES): Add msgl-fsearch.c.
 
-2009-09-15  Bruno Haible  <bruno@clisp.org>
+2008-09-15  Bruno Haible  <bruno@clisp.org>
 
        * msgcmp.c (use_fuzzy_matching): New variable.
        (long_options): Add option -N/--no-fuzzy-matching.
index 635f8c1369bc26e5a98cd992e41cf1b9f78cebcf..2f6c8377dbdcacf6a0350360374f68ecc85648af 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-1998, 2000-2007 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -332,10 +332,22 @@ cmp_by_msgid (const void *va, const void *vb)
 {
   const message_ty *a = *(const message_ty **) va;
   const message_ty *b = *(const message_ty **) vb;
-  /* Because msgids normally contain only ASCII characters, it is OK to
-     sort them as if we were in the C locale. And strcoll() in the C locale
-     is the same as strcmp().  */
-  return strcmp (a->msgid, b->msgid);
+
+  /* Because msgids normally contain only ASCII characters or are UTF-8
+     encoded, it is OK to sort them as if we were in a C.UTF-8 locale. And
+     strcoll() in a C.UTF-8 locale is the same as strcmp().  */
+  int cmp = strcmp (a->msgid, b->msgid);
+  if (cmp != 0)
+    return cmp;
+
+  /* If the msgids are equal, disambiguate by comparing the contexts.  */
+  if (a->msgctxt == b->msgctxt)
+    return 0;
+  if (a->msgctxt == NULL)
+    return -1;
+  if (b->msgctxt == NULL)
+    return 1;
+  return strcmp (a->msgctxt, b->msgctxt);
 }
 
 
@@ -420,10 +432,21 @@ cmp_by_filepos (const void *va, const void *vb)
     return cmp;
 
   /* If they are equal, compare on the msgid strings.  */
-  /* Because msgids normally contain only ASCII characters, it is OK to
-     sort them as if we were in the C locale. And strcoll() in the C locale
-     is the same as strcmp().  */
-  return strcmp (a->msgid, b->msgid);
+  /* Because msgids normally contain only ASCII characters or are UTF-8
+     encoded, it is OK to sort them as if we were in a C.UTF-8 locale. And
+     strcoll() in a C.UTF-8 locale is the same as strcmp().  */
+  cmp = strcmp (a->msgid, b->msgid);
+  if (cmp != 0)
+    return cmp;
+
+  /* If the msgids are equal, disambiguate by comparing the contexts.  */
+  if (a->msgctxt == b->msgctxt)
+    return 0;
+  if (a->msgctxt == NULL)
+    return -1;
+  if (b->msgctxt == NULL)
+    return 1;
+  return strcmp (a->msgctxt, b->msgctxt);
 }