{
struct substring ss = ss_cstr (SvPV_nolen (sv));
if ( ! data_in (ss, LEGACY_NATIVE, ifmt->type, 0, 0,
- sfi->dict,
- case_data_rw (c, v),
- var_get_width (v)) )
+ case_data_rw (c, v), var_get_width (v),
+ dict_get_encoding (sfi->dict)))
{
RETVAL = 0;
goto finish;
static int hexit_value (int c);
\f
/* Parses the characters in INPUT, which are encoded in the given
- ENCODING, according to FORMAT. Stores the parsed
- representation in OUTPUT, which the caller must have
- initialized with the given WIDTH (0 for a numeric field,
- otherwise the string width).
- Iff FORMAT is a string format, then DICT must be a pointer
- to the dictionary associated with OUTPUT. Otherwise, DICT
- may be null. */
+ INPUT_ENCODING, according to FORMAT.
+
+ Stores the parsed representation in OUTPUT, which the caller must have
+ initialized with the given WIDTH (0 for a numeric field, otherwise the
+ string width). If FORMAT is FMT_A, then OUTPUT_ENCODING must specify the
+ correct encoding for OUTPUT (normally obtained via dict_get_encoding()). */
bool
-data_in (struct substring input, const char *encoding,
+data_in (struct substring input, const char *input_encoding,
enum fmt_type format, int first_column, int last_column,
- const struct dictionary *dict, union value *output, int width)
+ union value *output, int width, const char *output_encoding)
{
static data_in_parser_func *const handlers[FMT_NUMBER_OF_FORMATS] =
{
else
{
/* Use the final output encoding. */
- dest_encoding = dict_get_encoding (dict);
+ dest_encoding = output_encoding;
}
}
if (dest_encoding != NULL)
{
- i.input = recode_substring_pool (dest_encoding, encoding, input, NULL);
+ i.input = recode_substring_pool (dest_encoding, input_encoding, input,
+ NULL);
s = i.input.string;
}
else
}
static bool
-has_implied_decimals (struct substring input, const char *encoding,
+has_implied_decimals (struct substring input, const char *input_encoding,
enum fmt_type format)
{
bool retval;
return false;
}
- s = recode_string (LEGACY_NATIVE, encoding,
+ s = recode_string (LEGACY_NATIVE, input_encoding,
ss_data (input), ss_length (input));
retval = (format == FMT_Z
? strchr (s, '.') == NULL
If it is appropriate, this function modifies the numeric value in OUTPUT. */
void
-data_in_imply_decimals (struct substring input, const char *encoding,
+data_in_imply_decimals (struct substring input, const char *input_encoding,
enum fmt_type format, int d, union value *output)
{
if (d > 0 && output->f != SYSMIS
- && has_implied_decimals (input, encoding, format))
+ && has_implied_decimals (input, input_encoding, format))
output->f /= pow (10., d);
}
\f
union value;
struct dictionary;
-bool data_in (struct substring input, const char *encoding,
- enum fmt_type, int first_column, int last_column,
- const struct dictionary *dict,
- union value *output, int width);
+bool data_in (struct substring input, const char *input_encoding,
+ enum fmt_type, int first_column, int last_column,
+ union value *output, int width, const char *output_encoding);
void data_in_imply_decimals (struct substring input, const char *encoding,
enum fmt_type format, int d, union value *output);
parse_fixed (const struct data_parser *parser, struct dfm_reader *reader,
struct ccase *c)
{
- const char *encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *input_encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *output_encoding = dict_get_encoding (parser->dict);
struct field *f;
int row;
f->format.w);
union value *value = case_data_rw_idx (c, f->case_idx);
- data_in (s, encoding, f->format.type,
+ data_in (s, input_encoding, f->format.type,
f->first_column, f->first_column + f->format.w,
- parser->dict, value, fmt_var_width (&f->format));
+ value, fmt_var_width (&f->format), output_encoding);
- data_in_imply_decimals (s, encoding, f->format.type, f->format.d,
- value);
+ data_in_imply_decimals (s, input_encoding, f->format.type,
+ f->format.d, value);
}
dfm_forward_record (reader);
parse_delimited_span (const struct data_parser *parser,
struct dfm_reader *reader, struct ccase *c)
{
- const char *encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *input_encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *output_encoding = dict_get_encoding (parser->dict);
struct string tmp = DS_EMPTY_INITIALIZER;
struct field *f;
}
}
- data_in (s, encoding, f->format.type, first_column, last_column,
- parser->dict,
+ data_in (s, input_encoding, f->format.type, first_column, last_column,
case_data_rw_idx (c, f->case_idx),
- fmt_var_width (&f->format));
+ fmt_var_width (&f->format), output_encoding);
}
ds_destroy (&tmp);
return true;
parse_delimited_no_span (const struct data_parser *parser,
struct dfm_reader *reader, struct ccase *c)
{
- const char *encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *input_encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *output_encoding = dict_get_encoding (parser->dict);
struct string tmp = DS_EMPTY_INITIALIZER;
struct substring s;
struct field *f, *end;
goto exit;
}
- data_in (s, encoding, f->format.type, first_column, last_column,
- parser->dict,
+ data_in (s, input_encoding, f->format.type, first_column, last_column,
case_data_rw_idx (c, f->case_idx),
- fmt_var_width (&f->format));
+ fmt_var_width (&f->format), output_encoding);
}
s = dfm_get_record (reader);
function NUMBER (string s, ni_format f)
{
union value out;
- data_in (ss_head (s, f->w), LEGACY_NATIVE, f->type, 0, 0, NULL, &out, 0);
+ data_in (ss_head (s, f->w), LEGACY_NATIVE, f->type, 0, 0, &out, 0, NULL);
data_in_imply_decimals (s, LEGACY_NATIVE, f->type, f->d, &out);
return out.f;
}
union value v;
assert (! (fmt_get_category (*format) & ( FMT_CAT_STRING )));
data_in (ds_ss (lex_tokstr (lexer)), LEGACY_NATIVE, *format, 0, 0,
- NULL, &v, 0);
+ &v, 0, NULL);
lex_get (lexer);
*x = v.f;
if (*x == SYSMIS)
flip_casereader_read (struct casereader *reader, void *flip_)
{
struct flip_pgm *flip = flip_;
+ const char *encoding;
struct ccase *c;
size_t i;
return false;
c = case_create (casereader_get_proto (reader));
- data_in (ss_cstr (flip->old_names.names[flip->cases_read]), dict_get_encoding (flip->dict),
- FMT_A,
- 0, 0,
- flip->dict,
- case_data_rw_idx (c, 0), 8);
-
+ encoding = dict_get_encoding (flip->dict);
+ data_in (ss_cstr (flip->old_names.names[flip->cases_read]), encoding,
+ FMT_A, 0, 0, case_data_rw_idx (c, 0), 8, encoding);
+
for (i = 0; i < flip->n_cases; i++)
{
double in;
/* Create destination variables, if needed.
This must be the final step; otherwise we'd have to
delete destination variables on failure. */
+ trns->dst_dict = dataset_dict (ds);
if (trns->src_vars != trns->dst_vars)
create_dst_vars (trns, dataset_dict (ds));
{
size_t i;
- trns->dst_dict = dict;
-
for (i = 0; i < trns->var_cnt; i++)
{
const struct variable **var = &trns->dst_vars[i];
find_src_string (struct recode_trns *trns, const uint8_t *value,
const struct variable *src_var)
{
- struct mapping *m;
+ const char *encoding = dict_get_encoding (trns->dst_dict);
int width = var_get_width (src_var);
+ struct mapping *m;
for (m = trns->mappings; m < trns->mappings + trns->map_cnt; m++)
{
msg_disable ();
match = data_in (ss_buffer (CHAR_CAST_BUG (char *, value), width),
- LEGACY_NATIVE, FMT_F, 0, 0, trns->dst_dict,
- &uv, 0);
+ LEGACY_NATIVE, FMT_F, 0, 0, &uv, 0, encoding);
msg_enable ();
out->value.f = uv.f;
break;
value_init (val, width);
msg_disable ();
- data_in (ss_cstr (text), UTF8, format->type, 0, 0, dict->dict, val, width);
+ data_in (ss_cstr (text), UTF8, format->type, 0, 0, val, width,
+ dict_get_encoding (dict->dict));
msg_enable ();
return val;
FALSE);
value_init (&value, width);
ok = (datasheet_get_value (ds->datasheet, casenum, idx, &value)
- && data_in (input, UTF8, fmt->type, 0, 0, dict->dict, &value, width)
+ && data_in (input, UTF8, fmt->type, 0, 0, &value, width,
+ dict_get_encoding (dict->dict))
&& datasheet_put_value (ds->datasheet, casenum, idx, &value));
value_destroy (&value, width);
{
msg_disable ();
- if (!data_in (field, LEGACY_NATIVE, in->type, 0, 0, ia->formats.dict,
- &val, var_get_width (var)))
+ if (!data_in (field, LEGACY_NATIVE, in->type, 0, 0, &val,
+ var_get_width (var), dict_get_encoding (ia->formats.dict)))
{
char fmt_string[FMT_STRING_LEN_MAX + 1];
fmt_to_string (in, fmt_string);
msg_disable ();
/* FIXME: UTF8 encoded strings will fail here */
ok = data_in (ss_cstr (s), LEGACY_NATIVE,
- format->type, 0, 0, NULL, &v_out, 0);
+ format->type, 0, 0, &v_out, 0, NULL);
msg_enable ();
if (ok && v_out.f == number)
{