dbp has asked for the wisdom of the Perl Monks concerning the following question:

The Perl API defines a C function "U8* bytes_to_utf8(U8 *s, STRLEN *len)". It is an experimental function, but one that is useful to me. What puzzles me is why the input is of type U8* if it converts from a standard string. Can I just pass in a char *? Also, how can one access all of these utf8 routines from a perl script (not using XS or Inline::C)?

Replies are listed 'Best First'.
Re: UTF8 question
by Zaxo (Archbishop) on Sep 24, 2002 at 00:35 UTC

    U8 is an unsigned octet, a typedef of unsigned char on most compilers. U8* is like unsigned char * which in C is also the type of an array or string of characters, as well as a pointer to a single character. An offset in the string or index into the array is simply added to the base pointer to get the offset reference.

    You'll need XS, Inline::C, or similar to make use of the API functions and macros.

    After Compline,
    Zaxo

      Thanks for the clarification of U8. I realize that I need XS or Inline::C to use API functions but are there perl functions that wrap any of the UTF8 stuff? The utf8 pragma doesn't seem to be what I'm looking for. There are a couple of modules on CPAN but what I'd really like to do is make sure a given string is utf8 inside the perl part of my module and fix it if it isn't (this can be a bit of a pain in c) and then do the lower level manipulation I need to do (using some c-only libraries) using Inline::C.

      This brings me to another question: Say a perl variable holds data encoded in utf8, if I pass that variable to a c function and SvPV the SV* will the c-style string I get back be utf8?