+/* Returns VAR's short name with the given IDX, if it has one
+ with that index, or a null pointer otherwise. Short names may
+ be sparse: even if IDX is less than the number of short names
+ in VAR, this function may return a null pointer. */
+const char *
+var_get_short_name (const struct variable *var, size_t idx)
+{
+ return idx < var->short_name_cnt ? var->short_names[idx] : NULL;
+}
+
+/* Sets VAR's short name with the given IDX to the UTF-8 string SHORT_NAME.
+ The caller must already have checked that, in the dictionary encoding,
+ SHORT_NAME is no more than SHORT_NAME_LEN bytes long. The new short name
+ will be converted to uppercase.
+
+ Specifying a null pointer for SHORT_NAME clears the specified short name. */
+void
+var_set_short_name (struct variable *var, size_t idx, const char *short_name)
+{
+ assert (short_name == NULL || id_is_plausible (short_name, false));
+
+ /* Clear old short name numbered IDX, if any. */
+ if (idx < var->short_name_cnt)
+ {
+ free (var->short_names[idx]);
+ var->short_names[idx] = NULL;
+ }
+
+ /* Install new short name for IDX. */
+ if (short_name != NULL)
+ {
+ if (idx >= var->short_name_cnt)
+ {
+ size_t old_cnt = var->short_name_cnt;
+ size_t i;
+ var->short_name_cnt = MAX (idx * 2, 1);
+ var->short_names = xnrealloc (var->short_names, var->short_name_cnt,
+ sizeof *var->short_names);
+ for (i = old_cnt; i < var->short_name_cnt; i++)
+ var->short_names[i] = NULL;
+ }
+ var->short_names[idx] = xstrdup (short_name);
+ str_uppercase (var->short_names[idx]);