Replace legacy_recode with recode_string.
[pspp-builds.git] / src / data / data-in.c
index eda6d1258f729b8d05352fb71fe1a24a0cdb1ef6..4666a173e7ce091d5fc185f99fdfc99dd2b9cea4 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <libpspp/assertion.h>
 #include <libpspp/legacy-encoding.h>
+#include <libpspp/i18n.h>
 #include <libpspp/compiler.h>
 #include <libpspp/integer-format.h>
 #include <libpspp/message.h>
@@ -53,7 +54,7 @@
 /* Information about parsing one data field. */
 struct data_in
   {
-    enum legacy_encoding encoding;/* Encoding of source. */
+    const char *encoding;       /* Encoding of source. */
     struct substring input;     /* Source. */
     enum fmt_type format;       /* Input format. */
     int implied_decimals;       /* Number of implied decimal places. */
@@ -100,7 +101,7 @@ static int hexit_value (int c);
    FIRST_COLUMN plus the length of the input because of the
    possibility of escaped quotes in strings, etc.) */
 bool
-data_in (struct substring input, enum legacy_encoding encoding,
+data_in (struct substring input, const char *encoding,
          enum fmt_type format, int implied_decimals,
          int first_column, int last_column, union value *output, int width)
 {
@@ -116,7 +117,7 @@ data_in (struct substring input, enum legacy_encoding encoding,
 
   assert ((width != 0) == fmt_is_string (format));
 
-  if (encoding == LEGACY_NATIVE
+  if (0 == strcmp (encoding, LEGACY_NATIVE)
       || fmt_get_category (format) & (FMT_CAT_BINARY | FMT_CAT_STRING))
     {
       i.input = input;
@@ -124,9 +125,12 @@ data_in (struct substring input, enum legacy_encoding encoding,
     }
   else
     {
+      char *s;
       ss_alloc_uninit (&i.input, ss_length (input));
-      legacy_recode (encoding, ss_data (input), LEGACY_NATIVE,
-                     ss_data (i.input), ss_length (input));
+
+      s = recode_string (LEGACY_NATIVE, encoding, ss_data (input), ss_length (input));
+      memcpy (ss_data (i.input), s, ss_length (input));
+      free (s);
       i.encoding = LEGACY_NATIVE;
       copy = ss_data (i.input);
     }
@@ -613,7 +617,9 @@ parse_A (struct data_in *i)
   const char *src = ss_data (i->input);
   size_t src_size = ss_length (i->input);
 
-  legacy_recode (i->encoding, src, LEGACY_NATIVE, dst, MIN (src_size, dst_size));
+  char *s = recode_string (LEGACY_NATIVE, i->encoding, src, MIN (src_size, dst_size));
+  memcpy (dst, s, dst_size);
+  free (s);
   if (dst_size > src_size)
     memset (&dst[src_size], ' ', dst_size - src_size);
 
@@ -639,7 +645,7 @@ parse_AHEX (struct data_in *i)
           return false;
         }
 
-      if (i->encoding != LEGACY_NATIVE)
+      if (0 != strcmp (i->encoding, LEGACY_NATIVE))
         {
           hi = legacy_to_native (i->encoding, hi);
           lo = legacy_to_native (i->encoding, lo);