X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fi18n.c;h=fbff1772a18b2748e21b2cb4a61a3b2f09734dae;hb=213a9dde780d4b31cdcf7dd14f5015633a89cec5;hp=e2893f3cdc8a8bb58cecf01c6ccc1298b18c0a63;hpb=9d1d71e732eeed85ca3002b264e1269cdd005a3f;p=pspp-builds.git diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index e2893f3c..fbff1772 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -609,7 +609,8 @@ i18n_done (void) { free (cvtr->tocode); free (cvtr->fromcode); - iconv_close (cvtr->conv); + if (cvtr->conv != (iconv_t) -1) + iconv_close (cvtr->conv); free (cvtr); } @@ -671,3 +672,52 @@ uc_name (ucs4_t uc, char buffer[16]) snprintf (buffer, 16, "U+%04X", uc); return buffer; } + +bool +get_encoding_info (struct encoding_info *e, const char *name) +{ + const struct substring in = SS_LITERAL_INITIALIZER ( + "\t\n\v\f\r " + "!\"#$%&'()*+,-./0123456789:;<=>?@" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~"); + + struct substring out, cr, lf; + bool ok; + + memset (e, 0, sizeof *e); + + cr = recode_substring_pool (name, "UTF-8", ss_cstr ("\r"), NULL); + lf = recode_substring_pool (name, "UTF-8", ss_cstr ("\n"), NULL); + ok = cr.length >= 1 && cr.length <= MAX_UNIT && cr.length == lf.length; + if (!ok) + { + fprintf (stderr, "warning: encoding `%s' is not supported.\n", name); + ss_dealloc (&cr); + ss_dealloc (&lf); + ss_alloc_substring (&cr, ss_cstr ("\r")); + ss_alloc_substring (&lf, ss_cstr ("\n")); + } + + e->unit = cr.length; + memcpy (e->cr, cr.string, e->unit); + memcpy (e->lf, lf.string, e->unit); + + ss_dealloc (&cr); + ss_dealloc (&lf); + + out = recode_substring_pool ("UTF-8", name, in, NULL); + e->is_ascii_compatible = ss_equals (in, out); + ss_dealloc (&out); + + return ok; +} + +bool +is_encoding_ascii_compatible (const char *encoding) +{ + struct encoding_info e; + + get_encoding_info (&e, encoding); + return e.is_ascii_compatible; +}