struct dictionary *
dict_create (const char *encoding)
{
- struct dictionary *d = xzalloc (sizeof *d);
+ struct dictionary *d = XZALLOC (struct dictionary);
d->encoding = xstrdup (encoding);
d->names_must_be_ids = true;
size_t ofs;
int mblen;
+ if (hint_len > ID_MAX_LEN)
+ hint_len = ID_MAX_LEN;
+
/* The allocation size here is OK: characters that are copied directly fit
OK, and characters that are not copied directly are replaced by a single
'_' byte. If u8_mbtouc() replaces bad input by 0xfffd, then that will get
if (hinted_name != NULL)
return hinted_name;
}
+
return make_numeric_name (dict, num_start);
}
void
dict_set_documents (struct dictionary *d, const struct string_array *new_docs)
{
- size_t i;
+ /* Swap out the old documents, instead of destroying them immediately, to
+ allow the new documents to include pointers into the old ones. */
+ struct string_array old_docs = STRING_ARRAY_INITIALIZER;
+ string_array_swap (&d->documents, &old_docs);
- dict_clear_documents (d);
-
- for (i = 0; i < new_docs->n; i++)
+ for (size_t i = 0; i < new_docs->n; i++)
dict_add_document_line (d, new_docs->strings[i], false);
+
+ string_array_destroy (&old_docs);
}
/* Replaces the documents for D by UTF-8 encoded string NEW_DOCS, dividing it
if (NULL == d)
return;
+ if (what & (VAR_TRAIT_WIDTH | VAR_TRAIT_POSITION))
+ invalidate_proto (d);
+
if (d->changed) d->changed (d, d->changed_data);
if (d->callbacks && d->callbacks->var_changed)
d->callbacks->var_changed (d, var_get_dict_index (v), what, oldvar, d->cb_data);