psppire-delimited-text: Clear entire 'cache_starts' buffer.
[pspp] / src / ui / gui / psppire-delimited-text.c
index b02a0ac9eabcf867d4575bdfed661b8d2f6faa7a..dd3715f6b97bb68a36bfefb855d980788daf9ed2 100644 (file)
@@ -63,14 +63,16 @@ count_delims (PsppireDelimitedText *tf)
     {
       gint enc = -1;
       // FIXME: Box these lines to avoid constant allocation/deallocation
-      gchar *foo = 0;
-      gtk_tree_model_get (tf->child, &iter, 1, &foo, -1);
+      gchar *line = NULL;
+      gtk_tree_model_get (tf->child, &iter, 1, &line, -1);
       {
-       char *line = foo;
+       char *p;
        gint count = 0;
-       while (*line)
+       for (p = line; ; p = g_utf8_find_next_char (p, NULL))
          {
-           const gunichar c = *line; //FIXME: Not multibyte safe!
+           const gunichar c = g_utf8_get_char (p);
+           if (c == 0)
+             break;
            if (enc == -1)
              {
                gint i;
@@ -96,18 +98,17 @@ count_delims (PsppireDelimitedText *tf)
                      count++;
                  }
              }
-           line++;
          }
        tf->max_delimiters = MAX (tf->max_delimiters, count);
       }
-      g_free (foo);
+      g_free (line);
     }
 }
 
 static void
 cache_invalidate (PsppireDelimitedText *tf)
 {
-  memset (tf->cache_starts, 0, 512);
+  memset (tf->cache_starts, 0, sizeof tf->cache_starts);
   if (tf->const_cache.string)
     {
       ss_dealloc (&tf->const_cache);
@@ -369,7 +370,7 @@ split_row_into_fields (PsppireDelimitedText *file, gint n)
       return;
     }
 
-  memset (file->cache_starts, 0, 512);
+  memset (file->cache_starts, 0, sizeof file->cache_starts);
   /* Cache miss */
   if (file->const_cache.string)
     {
@@ -582,7 +583,7 @@ psppire_delimited_text_init (PsppireDelimitedText *text_file)
   text_file->const_cache.string = NULL;
   text_file->const_cache.length = 0;
   text_file->cache_row = -1;
-  memset (text_file->cache_starts, 0, 512);
+  memset (text_file->cache_starts, 0, sizeof text_file->cache_starts);
 
   text_file->max_delimiters = 0;
 
@@ -591,15 +592,13 @@ psppire_delimited_text_init (PsppireDelimitedText *text_file)
 }
 
 
-GtkTreeModel *
+PsppireDelimitedText *
 psppire_delimited_text_new (GtkTreeModel *child)
 {
-  PsppireDelimitedText *retval =
+  return
     g_object_new (PSPPIRE_TYPE_DELIMITED_TEXT,
                  "child", child,
                  NULL);
-
-  return GTK_TREE_MODEL (retval);
 }
 
 static void