+/* Split row N into it's delimited fields (if it is not already cached)
+ and set this row as the current cache. */
+static void
+split_row_into_fields (PsppireDelimitedText *file, gint n)
+{
+ if (n == file->cache_row) /* Cache hit */
+ {
+ return;
+ }
+
+ memset (file->cache_starts, 0, 512);
+ /* Cache miss */
+ if (file->const_cache.string)
+ {
+ ss_dealloc (&file->const_cache);
+ }
+ ss_alloc_substring_pool (&file->const_cache,
+ PSPPIRE_TEXT_FILE (file->child)->lines[n], NULL);
+ struct substring cs = file->const_cache;
+ int field = 0;
+ file->cache_starts[0] = cs.string;
+ for (;
+ UINT32_MAX != ss_first_mb (cs);
+ ss_get_mb (&cs))
+ {
+ ucs4_t xx = ss_first_mb (cs);
+ GSList *del;
+ for (del = file->delimiters; del; del = g_slist_next (del))
+ {
+ if (xx == GPOINTER_TO_INT (del->data))
+ {
+ field++;
+ int char_len = ss_first_mblen (cs);
+ file->cache_starts[field] = cs.string + char_len;
+ while (char_len > 0)
+ {
+ cs.string[char_len - 1] = '\0';
+ char_len--;
+ }
+ break;
+ }
+ }
+ }
+
+ file->cache_row = n;
+}
+
+const gchar *
+psppire_delimited_text_get_header_title (PsppireDelimitedText *file, gint column)
+{
+ if (file->first_line <= 0)
+ return NULL;
+
+ split_row_into_fields (file, file->first_line - 1);
+
+ return file->cache_starts [column];
+}
+