ShiftJIS-CP932-MapUTF

 view release on metacpan or  search on metacpan

MapUTF.xs  view on Meta::CPAN

    FREETMPS;
    LEAVE;
}

static char* funcname_to[] = {
    "cp932_to_unicode",
    "cp932_to_utf8",
    "cp932_to_utf16le",
    "cp932_to_utf16be",
    "cp932_to_utf32le",
    "cp932_to_utf32be",
};

static char* funcname_fm[] = {
    "unicode_to_cp932",
    "utf8_to_cp932",
    "utf16le_to_cp932",
    "utf16be_to_cp932",
    "utf32le_to_cp932",
    "utf32be_to_cp932",
    "utf16_to_cp932",
    "utf32_to_cp932"
};

static STRLEN maxlen_to[] = {
    MaxLenToUni,
    MaxLenToU8,
    MaxLenToU16,
    MaxLenToU16,
    MaxLenToU32,
    MaxLenToU32,
};

static STRLEN maxlen_fm[] = {
    MaxLenFmUni,
    MaxLenFmU8,
    MaxLenFmU16,
    MaxLenFmU16,
    MaxLenFmU32,
    MaxLenFmU32,
    MaxLenFmU16,
    MaxLenFmU32,
};

static U8* (*app_uv_in[])(U8*, UV) = {
    NULL,
    app_in_utf8,
    app_in_utf16le,
    app_in_utf16be,
    app_in_utf32le,
    app_in_utf32be,
};

static UV (*ord_uv_in[])(U8 *, STRLEN, STRLEN *) = {
    NULL,
    ord_in_utf8,
    ord_in_utf16le,
    ord_in_utf16be,
    ord_in_utf32le,
    ord_in_utf32be,
    ord_in_utf16be, /* w/o BOM*/
    ord_in_utf32be, /* w/o BOM*/
};


MODULE = ShiftJIS::CP932::MapUTF	PACKAGE = ShiftJIS::CP932::MapUTF

PROTOTYPES: DISABLE

void
cp932_to_unicode(...)
  ALIAS:
    cp932_to_utf8    = 1
    cp932_to_utf16le = 2
    cp932_to_utf16be = 3
    cp932_to_utf32le = 4
    cp932_to_utf32be = 5
  PREINIT:
    SV *src, *dst, *cvref, *mod;
    STRLEN srclen, dstlen, modlen, mblen, ulen;
    U8 *s, *e, *p, *d, *m, *m_e, uni[UTF8_MAXLEN + 1];
    UV uv;
    struct leading lb;
    U8* (*app_uv)(U8*, UV);
    bool mod_g, mod_s, mod_t;
  PPCODE:
    STMT_ASSIGN_CVREF_AND_SRC(funcname_to[ix])
    if (SvUTF8(src)) {
	src = sv_mortalcopy(src);
	sv_utf8_downgrade(src, 0);
    }
    STMT_ASSIGN_LENDST(maxlen_to[ix])
    if (ix == 0)
	SvUTF8_on(dst);

    m = (U8*)SvPV(mod, modlen);
    for (p = m, m_e = m + modlen; p < m_e; p++) {
	if (*p == 'g' || *p == 's' || *p == 't')
	    continue;
    	croak("Unknown option in %s: '%c'", funcname_to[ix], *p);
    }
    mod_g = memchr((void*)m, 'g', modlen) != NULL;
    mod_s = memchr((void*)m, 's', modlen) != NULL;
    mod_t = memchr((void*)m, 't', modlen) != NULL;

    app_uv = app_uv_in[ix];

    if (cvref) {
	for (p = s; p < e; p += mblen) {
	    STMT_GET_MBLEN

	    if (!mblen) {
		sv_cat_retcvref(dst, cvref, newSVuv((UV)*p), TRUE);
		p++;
		continue;
	    }

	    STMT_GET_UV_FROM_MB

	    if (uv || !*p) {
		ulen = ix ? app_uv(uni, uv) - uni
			  : uvuni_to_utf8(uni, uv) - uni;



( run in 0.400 second using v1.01-cache-2.11-cpan-39bf76dae61 )