/* Converts TEXT to a value. VAL will be initialised and filled by this function. It is the caller's responsibility to destroy VAL when no longer needed. VAR must be the variable with which VAL is associated. On success, VAL is returned, NULL otherwise. */ union value * text_to_value (const gchar *text, const struct variable *var, union value *val) { const struct fmt_spec *format = var_get_print_format (var); int width = var_get_width (var); if ( format->type != FMT_A) { if ( ! text ) return NULL; { const gchar *s = text; while (*s) { if ( !isspace (*s)) break; s++; } if ( !*s) return NULL; } } value_init (val, width); free (data_in (ss_cstr (text), UTF8, format->type, val, width, var_get_encoding (var))); return val; }
static void acc (struct statistic *s, const struct ccase *cx, double c UNUSED, double cc UNUSED, double y) { struct box_whisker *bw = UP_CAST (s, struct box_whisker, parent.parent); bool extreme; struct outlier *o; if ( y > bw->hinges[2] + bw->step) /* Upper outlier */ { extreme = (y > bw->hinges[2] + 2 * bw->step) ; } else if (y < bw->hinges[0] - bw->step) /* Lower outlier */ { extreme = (y < bw->hinges[0] - 2 * bw->step) ; } else /* Not an outlier */ { if (bw->whiskers[0] == SYSMIS) bw->whiskers[0] = y; if (y > bw->whiskers[1]) bw->whiskers[1] = y; return; } /* y is an outlier */ o = xzalloc (sizeof *o) ; o->value = y; o->extreme = extreme; ds_init_empty (&o->label); if (bw->id_var) { char *s = data_out (case_data_idx (cx, bw->id_idx), var_get_encoding (bw->id_var), var_get_print_format (bw->id_var)); ds_put_cstr (&o->label, s); free (s); } else { ds_put_format (&o->label, "%ld", (casenumber) case_data_idx (cx, bw->id_idx)->f); } ll_push_head (&bw->outliers, &o->ll); }
/* Formats a value according to VAR's print format and strips white space appropriately for VAR's type. That is, if VAR is numeric, strips leading white space (because numbers are right-justified within their fields), and if VAR is string, strips trailing white space (because spaces pad out string values on the right). Returns an allocated string. The returned string must be freed when no longer required. */ gchar * value_to_text (union value v, const struct variable *var) { gchar *s; s = data_out (&v, var_get_encoding (var), var_get_print_format (var)); if (var_is_numeric (var)) g_strchug (s); else g_strchomp (s); return s; }
/* Perform data_out for case CC, variable V, appending to STRING */ static void data_out_g_string (GString *string, const struct variable *v, const struct ccase *cc) { const struct fmt_spec *fs = var_get_print_format (v); const union value *val = case_data (cc, v); char *s = data_out (val, var_get_encoding (v), fs); g_string_append (string, s); g_free (s); }