- if (idx >= 1 && idx <= vector_get_n_vars (v))
- {
- struct variable *var = vector_get_var (v, (size_t) idx - 1);
- return copy_string (e, CHAR_CAST_BUG (char *, case_str (c, var)),
- var_get_width (var));
- }
- else
- {
- if (idx == SYSMIS)
- msg_at (SE, expr_location (e, n->args[0]),
- _("SYSMIS is not a valid index value for %zu-element vector "
- "%s. The result will be set to the empty string."),
- vector_get_n_vars (v), vector_get_name (v));
- else
- msg_at (SE, expr_location (e, n->args[0]),
- _("%g is not a valid index value for %zu-element vector %s. "
- "The result will be set to the empty string."),
- idx, vector_get_n_vars (v), vector_get_name (v));
- return empty_string;
- }
+ const struct variable *var = expr_index_vector (e, n, v, idx);
+ return (var
+ ? copy_string (e, CHAR_CAST_BUG (char *, case_str (c, var)),
+ var_get_width (var))
+ : empty_string);