/* utf8.c
*
* Copyright (C) 2000, 2001, 2002, 2003, 2004, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
/*
* 'What a fix!' said Sam. 'That's the one place in all the lands we've ever
* heard of that we don't want to see any closer; and that's the one place
* we're trying to get to! And that's just where we can't get, nohow.'
*
* 'Well do I understand your speech,' he answered in the same language;
* 'yet few strangers do so. Why then do you not speak in the Common Tongue,
* as is the custom in the West, if you wish to be answered?'
*
* ...the travellers perceived that the floor was paved with stones of many
* hues; branching runes and strange devices intertwined beneath their feet.
*/
#include "EXTERN.h"
#define PERL_IN_UTF8_C
#include "perl.h"
/*
=head1 Unicode Support
=for apidoc A|U8 *|uvuni_to_utf8_flags|U8 *d|UV uv|UV flags
Adds the UTF-8 representation of the Unicode codepoint C<uv> to the end
of the string C<d>; C<d> should be have at least C<UTF8_MAXLEN+1> free
bytes available. The return value is the pointer to the byte after the
end of the new character. In other words,
d = uvuni_to_utf8_flags(d, uv, flags);
or, in most cases,
d = uvuni_to_utf8(d, uv);
(which is equivalent to)
d = uvuni_to_utf8_flags(d, uv, 0);
is the recommended Unicode-aware way of saying
*(d++) = uv;
=cut
*/
U8 *
{
if (UNICODE_IS_SURROGATE(uv) &&
!(flags & UNICODE_ALLOW_SURROGATE))
else if (
!(flags & UNICODE_ALLOW_FDD0))
||
!(flags & UNICODE_ALLOW_FFFF))) &&
/* UNICODE_ALLOW_SUPER includes
* FFFEs and FFFFs beyond 0x10FFFF. */
((uv <= PERL_UNICODE_MAX) ||
!(flags & UNICODE_ALLOW_SUPER))
)
}
if (UNI_IS_INVARIANT(uv)) {
return d;
}
#if defined(EBCDIC)
else {
while (p > d) {
}
return d+len;
}
#else /* Non loop style */
if (uv < 0x800) {
return d;
}
if (uv < 0x10000) {
return d;
}
if (uv < 0x200000) {
return d;
}
if (uv < 0x4000000) {
return d;
}
if (uv < 0x80000000) {
return d;
}
#ifdef HAS_QUAD
if (uv < UTF8_QUAD_MAX)
#endif
{
*d++ = 0xfe; /* Can't match U+FEFF! */
return d;
}
#ifdef HAS_QUAD
{
*d++ = 0xff; /* Can't match U+FFFE! */
*d++ = 0x80; /* 6 Reserved bits */
return d;
}
#endif
#endif /* Loop style */
}
U8 *
{
}
/*
=for apidoc A|STRLEN|is_utf8_char|U8 *s
Tests if some arbitrary number of bytes begins in a valid UTF-8
character. Note that an INVARIANT (i.e. ASCII) character is a valid
UTF-8 character. The actual number of bytes in the UTF-8 character
will be returned if it is valid, otherwise 0.
=cut */
{
U8 u = *s;
if (UTF8_IS_INVARIANT(u))
return 1;
if (!UTF8_IS_START(u))
return 0;
return 0;
s++;
u &= UTF_START_MASK(len);
uv = u;
while (slen--) {
if (!UTF8_IS_CONTINUATION(*s))
return 0;
return 0;
s++;
}
return 0;
return len;
}
/*
=for apidoc A|bool|is_utf8_string|U8 *s|STRLEN len
Returns true if first C<len> bytes of the given string form a valid
UTF-8 string, false otherwise. Note that 'a valid UTF-8 string' does
not mean 'a string that contains code points above 0x7F encoded in UTF-8'
because a valid ASCII string is a valid UTF-8 string.
=cut
*/
bool
{
U8* x = s;
STRLEN c;
if (!len)
while (x < send) {
/* Inline the easy bits of is_utf8_char() here for speed... */
if (UTF8_IS_INVARIANT(*x))
c = 1;
else if (!UTF8_IS_START(*x))
return FALSE;
else {
/* ... and call is_utf8_char() only if really needed. */
c = is_utf8_char(x);
if (!c)
return FALSE;
}
x += c;
}
if (x != send)
return FALSE;
return TRUE;
}
/*
=for apidoc A|bool|is_utf8_string_loc|U8 *s|STRLEN len|U8 **p
Like is_ut8_string but store the location of the failure in
the last argument.
=cut
*/
bool
{
U8* x = s;
STRLEN c;
if (!len)
while (x < send) {
/* Inline the easy bits of is_utf8_char() here for speed... */
if (UTF8_IS_INVARIANT(*x))
c = 1;
else if (!UTF8_IS_START(*x)) {
if (p)
*p = x;
return FALSE;
}
else {
/* ... and call is_utf8_char() only if really needed. */
c = is_utf8_char(x);
if (!c) {
if (p)
*p = x;
return FALSE;
}
}
x += c;
}
if (x != send) {
if (p)
*p = x;
return FALSE;
}
return TRUE;
}
/*
=for apidoc A|UV|utf8n_to_uvuni|U8 *s|STRLEN curlen|STRLEN *retlen|U32 flags
Bottom level UTF-8 decode routine.
Returns the unicode code point value of the first character in the string C<s>
which is assumed to be in UTF-8 encoding and no longer than C<curlen>;
C<retlen> will be set to the length, in bytes, of that character.
If C<s> does not point to a well-formed UTF-8 character, the behaviour
is dependent on the value of C<flags>: if it contains UTF8_CHECK_ONLY,
it is assumed that the caller will raise a warning, and this function
will silently just set C<retlen> to C<-1> and return zero. If the
C<flags> does not contain UTF8_CHECK_ONLY, warnings about
malformations will be given, C<retlen> will be set to the expected
length of the UTF-8 character in bytes, and zero will be returned.
The C<flags> can also contain various flags to allow deviations from
the strict UTF-8 encoding (see F<utf8.h>).
Most code should use utf8_to_uvchr() rather than call this directly.
=cut
*/
{
/* This list is a superset of the UTF8_ALLOW_XXX. */
if (curlen == 0 &&
!(flags & UTF8_ALLOW_EMPTY)) {
goto malformed;
}
if (UTF8_IS_INVARIANT(uv)) {
if (retlen)
*retlen = 1;
return (UV) (NATIVE_TO_UTF(*s));
}
if (UTF8_IS_CONTINUATION(uv) &&
!(flags & UTF8_ALLOW_CONTINUATION)) {
goto malformed;
}
!(flags & UTF8_ALLOW_NON_CONTINUATION)) {
goto malformed;
}
#ifdef EBCDIC
#else
!(flags & UTF8_ALLOW_FE_FF)) {
goto malformed;
}
#endif
#ifdef EBCDIC
#else
#endif
if (retlen)
!(flags & UTF8_ALLOW_SHORT)) {
goto malformed;
}
len--;
s++;
while (len--) {
if (!UTF8_IS_CONTINUATION(*s) &&
!(flags & UTF8_ALLOW_NON_CONTINUATION)) {
s--;
goto malformed;
}
else
/* These cannot be allowed. */
if (!(flags & UTF8_ALLOW_LONG)) {
goto malformed;
}
}
else { /* uv < ouv */
/* This cannot be allowed. */
goto malformed;
}
}
s++;
}
if (UNICODE_IS_SURROGATE(uv) &&
!(flags & UTF8_ALLOW_SURROGATE)) {
goto malformed;
!(flags & UTF8_ALLOW_LONG)) {
goto malformed;
} else if (UNICODE_IS_ILLEGAL(uv) &&
!(flags & UTF8_ALLOW_FFFF)) {
goto malformed;
}
return uv;
if (flags & UTF8_CHECK_ONLY) {
if (retlen)
*retlen = -1;
return 0;
}
if (dowarn) {
switch (warning) {
case 0: /* Intentionally empty. */ break;
case UTF8_WARN_EMPTY:
break;
case UTF8_WARN_CONTINUATION:
Perl_sv_catpvf(aTHX_ sv, "(unexpected continuation byte 0x%02"UVxf", with no preceding start byte)", uv);
break;
if (s == s0)
Perl_sv_catpvf(aTHX_ sv, "(unexpected non-continuation byte 0x%02"UVxf", immediately after start byte 0x%02"UVxf")",
else
Perl_sv_catpvf(aTHX_ sv, "(unexpected non-continuation byte 0x%02"UVxf", %d byte%s after start byte 0x%02"UVxf", expected %d bytes)",
break;
case UTF8_WARN_FE_FF:
break;
case UTF8_WARN_SHORT:
break;
case UTF8_WARN_OVERFLOW:
break;
case UTF8_WARN_SURROGATE:
break;
case UTF8_WARN_LONG:
break;
case UTF8_WARN_FFFF:
break;
default:
break;
}
if (warning) {
if (PL_op)
else
}
}
if (retlen)
return 0;
}
/*
=for apidoc A|UV|utf8_to_uvchr|U8 *s|STRLEN *retlen
Returns the native character value of the first character in the string C<s>
which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
length, in bytes, of that character.
If C<s> does not point to a well-formed UTF-8 character, zero is
returned and retlen is set, if possible, to -1.
=cut
*/
{
}
/*
=for apidoc A|UV|utf8_to_uvuni|U8 *s|STRLEN *retlen
Returns the Unicode code point of the first character in the string C<s>
which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
length, in bytes, of that character.
This function should only be used when returned UV is considered
an index into the Unicode semantic tables (e.g. swashes).
If C<s> does not point to a well-formed UTF-8 character, zero is
returned and retlen is set, if possible, to -1.
=cut
*/
{
/* Call the low level routine asking for checks */
}
/*
=for apidoc A|STRLEN|utf8_length|U8 *s|U8 *e
Return the length of the UTF-8 char encoded string C<s> in characters.
Stops at C<e> (inclusive). If C<e E<lt> s> or if the scan would end
up past C<e>, croaks.
=cut
*/
{
/* Note: cannot use UTF8_IS_...() too eagerly here since e.g.
* the bitops (especially ~) can create illegal UTF-8.
* In other words: in Perl UTF-8 is not just for Unicode. */
if (e < s) {
if (PL_op)
else
}
return 0;
}
while (s < e) {
if (e - s < t) {
if (PL_op)
else
}
return len;
}
s += t;
len++;
}
return len;
}
/*
=for apidoc A|IV|utf8_distance|U8 *a|U8 *b
Returns the number of UTF-8 characters between the UTF-8 pointers C<a>
and C<b>.
WARNING: use only if you *know* that the pointers point inside the
same UTF-8 buffer.
=cut
*/
{
/* Note: cannot use UTF8_IS_...() too eagerly here since e.g.
* the bitops (especially ~) can create illegal UTF-8.
* In other words: in Perl UTF-8 is not just for Unicode. */
if (a < b) {
while (a < b) {
if (b - a < c) {
if (PL_op)
else
}
return off;
}
a += c;
off--;
}
}
else {
while (b < a) {
if (a - b < c) {
if (PL_op)
else
}
return off;
}
b += c;
off++;
}
}
return off;
}
/*
=for apidoc A|U8 *|utf8_hop|U8 *s|I32 off
Return the UTF-8 pointer C<s> displaced by C<off> characters, either
forward or backward.
WARNING: do not use the following unless you *know* C<off> is within
the UTF-8 data pointed to by C<s> *and* that on entry C<s> is aligned
on the first byte of character or just after the last byte of a character.
=cut
*/
U8 *
{
/* Note: cannot use UTF8_IS_...() too eagerly here since e.g
* the bitops (especially ~) can create illegal UTF-8.
* In other words: in Perl UTF-8 is not just for Unicode. */
if (off >= 0) {
while (off--)
s += UTF8SKIP(s);
}
else {
while (off++) {
s--;
while (UTF8_IS_CONTINUATION(*s))
s--;
}
}
return s;
}
/*
=for apidoc A|U8 *|utf8_to_bytes|U8 *s|STRLEN *len
Converts a string C<s> of length C<len> from UTF-8 into byte encoding.
Unlike C<bytes_to_utf8>, this over-writes the original string, and
updates len to contain the new length.
Returns zero on failure, setting C<len> to -1.
=cut
*/
U8 *
{
U8 *d;
/* ensure valid UTF-8 and chars < 256 before updating string */
U8 c = *s++;
if (!UTF8_IS_INVARIANT(c) &&
(!UTF8_IS_DOWNGRADEABLE_START(c) || (s >= send)
|| !(c = *s++) || !UTF8_IS_CONTINUATION(c))) {
*len = -1;
return 0;
}
}
d = s = save;
while (s < send) {
s += ulen;
}
*d = '\0';
return save;
}
/*
=for apidoc A|U8 *|bytes_from_utf8|U8 *s|STRLEN *len|bool *is_utf8
Converts a string C<s> of length C<len> from UTF-8 into byte encoding.
Unlike <utf8_to_bytes> but like C<bytes_to_utf8>, returns a pointer to
the newly-created string, and updates C<len> to contain the new
length. Returns the original string if no conversion occurs, C<len>
is unchanged. Do nothing if C<is_utf8> points to 0. Sets C<is_utf8> to
0 if C<s> is converted or contains all 7bit characters.
=cut
*/
U8 *
{
U8 *d;
if (!*is_utf8)
return start;
/* ensure valid UTF-8 and chars < 256 before converting string */
U8 c = *s++;
if (!UTF8_IS_INVARIANT(c)) {
if (UTF8_IS_DOWNGRADEABLE_START(c) && s < send &&
(c = *s++) && UTF8_IS_CONTINUATION(c))
count++;
else
return start;
}
}
*is_utf8 = 0;
while (s < send) {
U8 c = *s++;
if (!UTF8_IS_INVARIANT(c)) {
/* Then it is two-byte encoded */
c = UTF8_ACCUMULATE(NATIVE_TO_UTF(c), *s++);
c = ASCII_TO_NATIVE(c);
}
*d++ = c;
}
*d = '\0';
return start;
}
/*
=for apidoc A|U8 *|bytes_to_utf8|U8 *s|STRLEN *len
Converts a string C<s> of length C<len> from ASCII into UTF-8 encoding.
Returns a pointer to the newly-created string, and sets C<len> to
reflect the new length.
If you want to convert to UTF-8 from other encodings than ASCII,
see sv_recode_to_utf8().
=cut
*/
U8*
{
U8 *d;
dst = d;
while (s < send) {
if (UNI_IS_INVARIANT(uv))
else {
}
}
*d = '\0';
return dst;
}
/*
* Convert native (big-endian) or reversed (little-endian) UTF-16 to UTF-8.
*
* Destination must be pre-extended to 3/2 source. Do not use in-place.
* We optimize for native, for obvious reasons. */
U8*
{
if (bytelen & 1)
while (p < pend) {
p += 2;
if (uv < 0x80) {
continue;
}
if (uv < 0x800) {
continue;
}
p += 2;
}
if (uv < 0x10000) {
continue;
}
else {
continue;
}
}
return d;
}
/* Note: this one is slightly destructive of the source. */
U8*
{
while (s < send) {
s[0] = s[1];
s[1] = tmp;
s += 2;
}
}
/* for now these are all defined (inefficiently) in terms of the utf8 versions */
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_alnum(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_alnumc(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_idfirst(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_alpha(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_ascii(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_space(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_digit(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_upper(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_lower(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_cntrl(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_graph(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_print(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_punct(tmpbuf);
}
bool
{
uvchr_to_utf8(tmpbuf, c);
return is_utf8_xdigit(tmpbuf);
}
{
uvchr_to_utf8(p, c);
return to_utf8_upper(p, p, lenp);
}
{
uvchr_to_utf8(p, c);
return to_utf8_title(p, p, lenp);
}
{
uvchr_to_utf8(p, c);
return to_utf8_lower(p, p, lenp);
}
{
uvchr_to_utf8(p, c);
return to_utf8_fold(p, p, lenp);
}
/* for now these all assume no locale info available for Unicode > 255 */
bool
{
return is_uni_alnum(c); /* XXX no locale support yet */
}
bool
{
return is_uni_alnumc(c); /* XXX no locale support yet */
}
bool
{
return is_uni_idfirst(c); /* XXX no locale support yet */
}
bool
{
return is_uni_alpha(c); /* XXX no locale support yet */
}
bool
{
return is_uni_ascii(c); /* XXX no locale support yet */
}
bool
{
return is_uni_space(c); /* XXX no locale support yet */
}
bool
{
return is_uni_digit(c); /* XXX no locale support yet */
}
bool
{
return is_uni_upper(c); /* XXX no locale support yet */
}
bool
{
return is_uni_lower(c); /* XXX no locale support yet */
}
bool
{
return is_uni_cntrl(c); /* XXX no locale support yet */
}
bool
{
return is_uni_graph(c); /* XXX no locale support yet */
}
bool
{
return is_uni_print(c); /* XXX no locale support yet */
}
bool
{
return is_uni_punct(c); /* XXX no locale support yet */
}
bool
{
return is_uni_xdigit(c); /* XXX no locale support yet */
}
{
/* XXX returns only the first character -- do not use XXX */
/* XXX no locale support yet */
}
{
/* XXX returns only the first character XXX -- do not use XXX */
/* XXX no locale support yet */
}
{
/* XXX returns only the first character -- do not use XXX */
/* XXX no locale support yet */
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_alnum)
/* NOTE: "IsWord", not "IsAlnum", since Alnum is a true
* descendant of isalnum(3), in other words, it doesn't
* contain the '_'. --jhi */
/* return *p == '_' || is_utf8_alpha(p) || is_utf8_digit(p); */
#ifdef SURPRISINGLY_SLOWER /* probably because alpha is usually true */
if (!PL_utf8_alnum)
#endif
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_alnum)
/* return is_utf8_alpha(p) || is_utf8_digit(p); */
#ifdef SURPRISINGLY_SLOWER /* probably because alpha is usually true */
if (!PL_utf8_alnum)
#endif
}
bool
{
if (*p == '_')
return TRUE;
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_idstart) /* is_utf8_idstart would be more logical. */
}
bool
{
if (*p == '_')
return TRUE;
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_idcont)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_alpha)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_ascii)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_space)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_digit)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_upper)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_lower)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_cntrl)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_graph)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_print)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_punct)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_xdigit)
}
bool
{
if (!is_utf8_char(p))
return FALSE;
if (!PL_utf8_mark)
}
/*
=for apidoc A|UV|to_utf8_case|U8 *p|U8* ustrp|STRLEN *lenp|SV **swash|char *normal|char *special
The "p" contains the pointer to the UTF-8 string encoding
the character that is being converted.
The "ustrp" is a pointer to the character buffer to put the
conversion result to. The "lenp" is a pointer to the length
of the result.
The "swashp" is a pointer to the swash to use.
and loaded by SWASHGET, using lib/utf8_heavy.pl. The special (usually,
but not always, a multicharacter mapping), is tried first.
The "special" is a string like "utf8::ToSpecLower", which means the
hash %utf8::ToSpecLower. The access to the hash is through
Perl_to_utf8_case().
The "normal" is a string like "ToLower" which means the swash
%utf8::ToLower.
=cut */
{
uv0 = utf8_to_uvchr(p, 0);
/* The NATIVE_TO_UNI() and UNI_TO_NATIVE() mappings
* are necessary in EBCDIC, they are redundant no-ops
* in ASCII-ish platforms, and hopefully optimized away. */
if (!*swashp) /* load on-demand */
/* The 0xDF is the only special casing Unicode code point below 0x100. */
/* It might be "special" (sometimes, but not always,
* a multicharacter mapping) */
(*svp)) {
char *s;
if (len == 1)
else {
#ifdef EBCDIC
/* If we have EBCDIC we need to remap the characters
* since any characters in the low 256 are Unicode
* code points, not EBCDIC. */
d = tmpbuf;
while (t < tend) {
if (tlen > 0) {
d = uvchr_to_utf8(d, UNI_TO_NATIVE(c));
t += tlen;
}
else
break;
}
}
else {
while (t < tend) {
d = uvchr_to_utf8(d, UNI_TO_NATIVE(*t));
t++;
}
}
#else
#endif
}
}
}
if (uv2) {
/* It was "normal" (a single character mapping). */
}
}
if (!len) /* Neither: just copy. */
if (lenp)
}
/*
=for apidoc A|UV|to_utf8_upper|U8 *p|U8 *ustrp|STRLEN *lenp
Convert the UTF-8 encoded character at p to its uppercase version and
store that in UTF-8 in ustrp and its length in bytes in lenp. Note
that the ustrp needs to be at least UTF8_MAXLEN_UCLC+1 bytes since the
uppercase version may be longer than the original character (up to two
characters).
The first character of the uppercased version is returned
(but note, as explained above, that there may be more.)
=cut */
{
}
/*
=for apidoc A|UV|to_utf8_title|U8 *p|U8 *ustrp|STRLEN *lenp
Convert the UTF-8 encoded character at p to its titlecase version and
store that in UTF-8 in ustrp and its length in bytes in lenp. Note
that the ustrp needs to be at least UTF8_MAXLEN_UCLC+1 bytes since the
titlecase version may be longer than the original character (up to two
characters).
The first character of the titlecased version is returned
(but note, as explained above, that there may be more.)
=cut */
{
}
/*
=for apidoc A|UV|to_utf8_lower|U8 *p|U8 *ustrp|STRLEN *lenp
Convert the UTF-8 encoded character at p to its lowercase version and
store that in UTF-8 in ustrp and its length in bytes in lenp. Note
that the ustrp needs to be at least UTF8_MAXLEN_UCLC+1 bytes since the
lowercase version may be longer than the original character (up to two
characters).
The first character of the lowercased version is returned
(but note, as explained above, that there may be more.)
=cut */
{
}
/*
=for apidoc A|UV|to_utf8_fold|U8 *p|U8 *ustrp|STRLEN *lenp
Convert the UTF-8 encoded character at p to its foldcase version and
store that in UTF-8 in ustrp and its length in bytes in lenp. Note
that the ustrp needs to be at least UTF8_MAXLEN_FOLD+1 bytes since the
foldcase version may be longer than the original character (up to
three characters).
The first character of the foldcased version is returned
(but note, as explained above, that there may be more.)
=cut */
{
}
/* a "swash" is a swatch hash */
SV*
{
dSP;
}
PL_hints = 0;
if (IN_PERL_COMPILETIME) {
/* XXX ought to be handled by lex_start */
PL_in_my = 0;
}
else
retval = &PL_sv_undef;
if (IN_PERL_COMPILETIME) {
}
retval);
}
return retval;
}
/* This API is wrong for special case conversions since we may need to
* return several Unicode characters for a single Unicode character
* (see lib/unicore/SpecCase.txt) The SWASHGET in lib/utf8_heavy.pl is
* the lower-level routine, and it is similarly broken for returning
* multiple values. --jhi */
{
if (!do_utf8 && !UNI_IS_INVARIANT(c)) {
}
/* Given a UTF-X encoded char 0xAA..0xYY,0xZZ
* then the "swatch" is a vec() for al the chars which start
* with 0xAA..0xYY
* So the key in the hash (klen) is length of encoded char -1
*/
if (klen == 0)
{
/* If char in invariant then swatch is for all the invariant chars
* In both UTF-8 and UTF-8-MOD that happens to be UTF_CONTINUATION_MARK
*/
}
else
{
/* If char is encoded then swatch is for the prefix */
}
/*
* This single-entry cache saves about 1/3 of the utf8 overhead in test
* suite. (That is, only 7-8% overall over just a hash cache. Still,
* it's nothing to sniff at.) Pity we usually come through at least
* two function calls to get here...
*
* NB: this code assumes that swatches are never modified, once generated!
*/
if (hv == PL_last_swash_hv &&
klen == PL_last_swash_klen &&
{
}
else {
/* Try our second-level swatch cache, kept in a hash. */
/* If not cached, generate it via utf8::SWASHGET */
dSP;
/* We use utf8n_to_uvuni() as we want an index into
Unicode tables, not a native character number.
*/
0 : UTF8_ALLOW_ANY);
/* On EBCDIC & ~(0xA0-1) isn't a useful thing to do */
else
retval = &PL_sv_undef;
if (IN_PERL_COMPILETIME)
}
if (klen)
}
case 1:
off >>= 3;
case 8:
case 16:
off <<= 1;
case 32:
off <<= 2;
}
return 0;
}
/*
=for apidoc A|U8 *|uvchr_to_utf8|U8 *d|UV uv
Adds the UTF-8 representation of the Native codepoint C<uv> to the end
of the string C<d>; C<d> should be have at least C<UTF8_MAXLEN+1> free
bytes available. The return value is the pointer to the byte after the
end of the new character. In other words,
d = uvchr_to_utf8(d, uv);
is the recommended wide native character-aware way of saying
*(d++) = uv;
=cut
*/
/* On ASCII machines this is normally a macro but we want a
real function in case XS code wants it
*/
U8 *
{
}
U8 *
{
}
/*
=for apidoc A|UV|utf8n_to_uvchr|U8 *s|STRLEN curlen|STRLEN *retlen|U32 flags
Returns the native character value of the first character in the string C<s>
which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
length, in bytes, of that character.
Allows length and flags to be passed to low level routine.
=cut
*/
/* On ASCII machines this is normally a macro but we want
a real function in case XS code wants it
*/
{
return UNI_TO_NATIVE(uv);
}
/*
=for apidoc A|char *|pv_uni_display|SV *dsv|U8 *spv|STRLEN len|STRLEN pvlim|UV flags
Build to the scalar dsv a displayable version of the string spv,
length len, the displayable version being at most pvlim bytes long
(if longer, the rest is truncated and "..." will be appended).
The flags argument can have UNI_DISPLAY_ISPRINT set to display
isPRINT()able characters as themselves, UNI_DISPLAY_BACKSLASH
to display the \\[nrfta\\] as the backslashed versions (like '\n')
(UNI_DISPLAY_BACKSLASH is preferred over UNI_DISPLAY_ISPRINT for \\).
UNI_DISPLAY_QQ (and its alias UNI_DISPLAY_REGEX) have both
UNI_DISPLAY_BACKSLASH and UNI_DISPLAY_ISPRINT turned on.
The pointer to the PV of the dsv is returned.
=cut */
char *
{
int truncated = 0;
char *s, *e;
UV u;
truncated++;
break;
}
u = utf8_to_uvchr((U8*)s, 0);
if (u < 256) {
switch (u & 0xFF) {
case '\n':
case '\r':
case '\t':
case '\f':
case '\a':
case '\\':
default: break;
}
}
/* isPRINT() is the locale-blind version. */
}
}
if (!ok)
}
if (truncated)
}
/*
=for apidoc A|char *|sv_uni_display|SV *dsv|SV *ssv|STRLEN pvlim|UV flags
Build to the scalar dsv a displayable version of the scalar sv,
the displayable version being at most pvlim bytes long
(if longer, the rest is truncated and "..." will be appended).
The flags argument is as in pv_uni_display().
The pointer to the PV of the dsv is returned.
=cut */
char *
{
}
/*
=for apidoc A|I32|ibcmp_utf8|const char *s1|char **pe1|register UV l1|bool u1|const char *s2|char **pe2|register UV l2|bool u2
Return true if the strings s1 and s2 differ case-insensitively, false
if not (if they are equal case-insensitively). If u1 is true, the
string s1 is assumed to be in UTF-8-encoded Unicode. If u2 is true,
the string s2 is assumed to be in UTF-8-encoded Unicode. If u1 or u2
are false, the respective string is assumed to be in native 8-bit
encoding.
If the pe1 and pe2 are non-NULL, the scanning pointers will be copied
in there (they will point at the beginning of the I<next> character).
If the pointers behind pe1 or pe2 are non-NULL, they are the end
pointers beyond which scanning will not continue under any
circustances. If the byte lengths l1 and l2 are non-zero, s1+l1 and
s2+l2 will be used as goal end pointers that will also stop the scan,
and which qualify towards defining a successful match: all the scans
that define an explicit length must reach their goal pointers for
a match to succeed).
For case-insensitiveness, the "casefolding" of Unicode is used
instead of upper/lowercasing both the characters, see
http://www.unicode.org/unicode/reports/tr21/ (Case Mappings).
=cut */
Perl_ibcmp_utf8(pTHX_ const char *s1, char **pe1, register UV l1, bool u1, const char *s2, char **pe2, register UV l2, bool u2)
{
bool match;
if (pe1)
if (pe2)
return 1; /* mismatch; possible infinite loop or false positive */
if (n1 == 0) {
if (u1)
else {
}
}
if (n2 == 0) {
if (u2)
else {
}
}
return 1; /* mismatch */
}
if (n1 == 0)
if (n2 == 0)
}
/* A match is defined by all the scans that specified
* an explicit length reaching their final goals. */
if (match) {
if (pe1)
if (pe2)
}
}