struct substring haystack,
struct substring needle,
struct substring replacement,
- double n)
+ int n)
{
- if (!needle.length
- || haystack.length < needle.length
- || n <= 0
- || n == SYSMIS)
+ if (!needle.length || haystack.length < needle.length || n <= 0)
return haystack;
struct substring result = alloc_string (e, MAX_STRING);
: n % 2 ? a[n / 2]
: (a[n / 2 - 1] + a[n / 2]) / 2.0);
}
+
+const struct variable *
+expr_index_vector (const struct expression *e, const struct expr_node *n,
+ const struct vector *v, double idx)
+{
+ if (idx >= 1 && idx <= vector_get_n_vars (v))
+ return vector_get_var (v, idx - 1);
+
+ msg_at (SE, expr_location (e, n),
+ _("Index outside valid range 1 to %zu, inclusive, for vector %s. "
+ "The value will be treated as system-missing."),
+ vector_get_n_vars (v), vector_get_name (v));
+ if (idx == SYSMIS)
+ msg_at (SN, expr_location (e, n->args[0]),
+ _("The index is system-missing."));
+ else
+ msg_at (SN, expr_location (e, n->args[0]),
+ _("The index has value %g."), idx);
+ return NULL;
+}