perl-unicode

RE: converting between utf8 and bytes

2000-07-03 19:16:07


I second that. One needs to be able to say: "this
scalar contains utf8 already - treat it like that".

I'm officially not working on Unicode right now, but
this is an XS extension which does what you want.
Needs to be turned into a full package, and I don't
have the inclination right now.

     if (Unicode::Fix::utf8on($a)) {
          $a is now treated as utf8
     }


#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifdef __cplusplus
extern "C"
#endif
XS(XS_Unicode__Fix_utf8on)
{
    dXSARGS;
    if (!is_utf_string(SvPV(*sp,PL_na))
        XSRETURN(0);
    SvUTF8_on(*sp);
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS(XS_Unicode__Fix_utf8off)
{
    dXSARGS;
    ENTER;
    SvUTF8_off(*sp);
}

#ifdef __cplusplus
extern "C"
#endif
XS(XS_Unicode__Fix_isutf8)
{
    dXSARGS;
    dTARG;
    ENTER;
    if(SvUTF8(POPs)) /* Ouch */
        XSRETURN_YES;
    else
        XSRETURN_NO;
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_Unicode__Fix)
{
    dXSARGS;
    char* file = __FILE__;

    XS_VERSION_BOOTCHECK ;

        newXS("Unicode::Fix::utf8on", XS_Unicode__Fix_utf8on, file);
        newXS("Unicode::Fix::utf8off", XS_Unicode__Fix_utf8off, file);
        newXS("Unicode::Fix::isutf8", XS_Unicode__Fix_isutf8, file);
    XSRETURN_YES;
}
----------------------------------------------------------------
The information transmitted is intended only for the person or entity to which
it is addressed and may contain confidential and/or privileged material.  Any
review, retransmission, dissemination or other use of, or taking of any action
in reliance upon, this information by persons or entities other than the
intended recipient is prohibited.   If you received this in error, please
contact the sender and delete the material from any computer.


<Prev in Thread] Current Thread [Next in Thread>