Encoding-FixLatin-XS

 view release on metacpan or  search on metacpan

XS.xs  view on Meta::CPAN

        cp = in[0] & 0x03;
        bytes = 5;
        min_cp = 0x200000;
    }
    else {
        return(0);
    }

    for(i = 1; i < bytes; i++) {
        if((in[i] & 0xC0) != 0x80) {
            return(0);
        }
        cp <<= 6;
        cp += in[i] & 0x3F;
    }

    if(overlong_fatal && cp < min_cp) {
        exception = newSV(48);
        SvPOK_on(exception);
        sv_catpv(exception, "Over-long UTF-8 byte sequence:");
        for(i = 0; i < bytes; i++) {
            sprintf(ebuf, " %02X", (int)in[i]);
            sv_catpv(exception, ebuf);
        }
        croak_sv(exception);
    }
    d = uvchr_to_utf8(out, cp);
    *d = '\0';
    return(bytes);
}


static int consume_latin_byte(U8* in, U8* out, int ascii_hex) {
    U8 *d, *utf_bytes;

    if(in[0] > 0x9F) {
        d = uvchr_to_utf8(out, (UV)in[0]);
        *d = '\0';
    }
    else {
        utf_bytes = _encoding_fix_latin_ms_map + (in[0] & 0x7F) * 4;
        if(ascii_hex == 0 && *utf_bytes == '%') {
            d = uvchr_to_utf8(out, (UV)in[0]);
            *d = '\0';
        }
        else {
            strncpy(out, utf_bytes, 4);
        }
    }
    return(1);
}


MODULE = Encoding::FixLatin::XS   PACKAGE = Encoding::FixLatin::XS

SV *
_fix_latin_xs(source, overlong_fatal, ascii_hex)
        SV *  source
        int   overlong_fatal
        int   ascii_hex
    PPCODE:
        ST(0) = _encoding_fix_latin_xs(source, overlong_fatal, ascii_hex);
        XSRETURN(1);



( run in 1.294 second using v1.01-cache-2.11-cpan-71847e10f99 )