? gdk/semantic.cache
? gdk-pixbuf/semantic.cache
? gtk/.emacs.desktop
? gtk/semantic.cache
? modules/input/semantic.cache
Index: gtk/gtkfilesystem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesystem.c,v
retrieving revision 1.39.2.1
diff -u -u -r1.39.2.1 gtkfilesystem.c
--- gtk/gtkfilesystem.c	20 Mar 2005 06:25:27 -0000	1.39.2.1
+++ gtk/gtkfilesystem.c	18 May 2005 21:14:59 -0000
@@ -115,6 +115,142 @@
   return info->display_name;
 }
 
+static gchar*
+collate_key_from_filename(const char *filename)
+{
+  /* In order to sort filenames correctly, the dot '.' must be treated as a
+   * special case since most l10n dictionary orderings seem to consider it
+   * insignificant, thus producing the ordering "event.c" "eventgenerator.c"
+   * "event.h" instead of "event.c" "event.h" "eventgenerator.c". Also, we
+   * would like to treat numbers intelligently so that "file1" "file10" "file5"
+   * is sorted as "file1" "file5" "file10".
+   *
+   * To achieve this, split the filename into collatable substrings which do
+   * not contain [.0-9] and special-cased substrings. The collatable substrings
+   * are run through the normal g_utf8_collate_key and the resulting keys are
+   * concatenated with keys generated from the special-cased substrings.
+   *
+   * Special cases: Dots are handled by replacing them with '\1' which implies
+   * that short dot-delimited substrings are before long ones, e.g.
+   * 
+   *   a\1a   (a.a)
+   *   a-\1a  (a-.a)
+   *   aa\1a  (aa.a)
+   * 
+   * Numbers are handled by prepending to each number d-1 superdigits where d =
+   * number of digits in the number and SUPERDIGIT is a character with an
+   * integer value higher than any digit (for instance ':'). This ensures that
+   * single-digit numbers are sorted before double-digit numbers which in turn
+   * are sorted separately from triple-digit numbers, etc. To avoid strange
+   * side-effects when sorting strings that already contain SUPERDIGITs, a '\2'
+   * is also prepended, like this
+   *
+   *   file\21      (file1)
+   *   file\25      (file5)
+   *   file\2:10    (file10)
+   *   file\2:26    (file26)
+   *   file\2::100  (file100)
+   *   file:foo     (file:foo)
+   * 
+   * This has the side-effect of sorting numbers before everything else (except
+   * dots), but this is probably OK.
+   */
+
+  GString *result;
+  const char *p;
+  const char *tmp_p;
+  const char *prev;
+  char *collate_key;
+  int digits;
+
+  
+  result = g_string_sized_new (strlen(filename) * 2);
+  
+  for (prev = p = filename; *p != '\0'; p = g_utf8_next_char (p))
+    {
+      gunichar c = g_utf8_get_char (p);
+
+      switch (c)
+	{
+	case '.':
+	  if (prev != p) {
+	    collate_key = g_utf8_collate_key (prev, p - prev);
+	    g_string_append (result, collate_key);
+	    g_free (collate_key);
+	  }
+	  
+	  g_string_append_c (result, '\1');
+
+	  /* skip the dot */
+	  prev = g_utf8_next_char (p);
+	  break;
+
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	case '4':
+	case '5':
+	case '6':
+	case '7':
+	case '8':
+	case '9':
+	  if (prev != p) {
+	    collate_key = g_utf8_collate_key (prev, p - prev);
+	    g_string_append (result, collate_key);
+	    g_free (collate_key);
+	  }
+	  
+	  g_string_append_c (result, '\2');
+
+	  prev = p;
+
+	  /* write d-1 colons */
+	  digits = 1;
+	  do
+	    {
+	      gunichar next_c;
+	      
+	      tmp_p = p;
+	      p = g_utf8_next_char (p);
+	      
+	      next_c = g_utf8_get_char (p);
+	      if (next_c >= '0' && next_c <= '9')
+		++digits;
+	      else
+		break;
+	    }
+	  while (*p != '\0');
+
+	  while (digits > 1)
+	    {
+	      g_string_append_c (result, ':');
+	      --digits;
+	    }
+	  
+	  /* write the number itself */
+	  g_string_append_len (result, prev, p - prev);
+
+	  prev = p;
+	  p = tmp_p;	  /* go one step back to avoid disturbing outer loop */
+	  break;
+	  
+	default:
+	  /* other characters just accumulate */
+	  break;
+	}
+    }
+  
+  if (prev != p) {
+    collate_key = g_utf8_collate_key (prev, p - prev);
+    g_string_append (result, collate_key);
+    g_free (collate_key);
+  }
+  
+  return g_string_free (result, FALSE);
+}
+
+
 /**
  * gtk_file_info_get_display_key:
  * @info: a #GtkFileInfo
@@ -135,7 +271,7 @@
     {
       /* Since info->display_key is only a cache, we cast off the const
        */
-      ((GtkFileInfo *)info)->display_key = g_utf8_collate_key (info->display_name, -1);
+      ((GtkFileInfo *)info)->display_key = collate_key_from_filename (info->display_name);
     }
 	
   return info->display_key;
