This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
clean numbered core dumps and t/tmp[0-9]*.
[perl5.git] / utf8.c
diff --git a/utf8.c b/utf8.c
index 5796534..dfe3092 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -25,8 +25,8 @@
 
 /* Unicode support */
 
-char *
-uv_to_utf8(unsigned char *d, UV uv)
+U8 *
+uv_to_utf8(U8 *d, UV uv)
 {
     if (uv < 0x80) {
        *d++ = uv;
@@ -96,7 +96,7 @@ uv_to_utf8(unsigned char *d, UV uv)
 }
 
 UV
-utf8_to_uv(unsigned char* s, I32* retlen)
+utf8_to_uv(U8* s, I32* retlen)
 {
     UV uv = *s;
     int len;
@@ -140,7 +140,7 @@ utf8_to_uv(unsigned char* s, I32* retlen)
 /* utf8_distance(a,b) is intended to be a - b in pointer arithmetic */
 
 I32
-utf8_distance(unsigned char *a, unsigned char *b)
+utf8_distance(U8 *a, U8 *b)
 {
     I32 off = 0;
     if (a < b) {
@@ -161,7 +161,7 @@ utf8_distance(unsigned char *a, unsigned char *b)
 /* WARNING: do not use the following unless you *know* off is within bounds */
 
 U8 *
-utf8_hop(unsigned char *s, I32 off)
+utf8_hop(U8 *s, I32 off)
 {
     if (off >= 0) {
        while (off--)
@@ -248,7 +248,7 @@ utf16_to_utf8_reversed(U16* p, U8* d, I32 bytelen)
 bool
 is_uni_alnum(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_alnum(tmpbuf);
 }
@@ -256,7 +256,7 @@ is_uni_alnum(U32 c)
 bool
 is_uni_idfirst(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_idfirst(tmpbuf);
 }
@@ -264,7 +264,7 @@ is_uni_idfirst(U32 c)
 bool
 is_uni_alpha(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_alpha(tmpbuf);
 }
@@ -272,7 +272,7 @@ is_uni_alpha(U32 c)
 bool
 is_uni_space(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_space(tmpbuf);
 }
@@ -280,7 +280,7 @@ is_uni_space(U32 c)
 bool
 is_uni_digit(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_digit(tmpbuf);
 }
@@ -288,7 +288,7 @@ is_uni_digit(U32 c)
 bool
 is_uni_upper(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_upper(tmpbuf);
 }
@@ -296,7 +296,7 @@ is_uni_upper(U32 c)
 bool
 is_uni_lower(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_lower(tmpbuf);
 }
@@ -304,7 +304,7 @@ is_uni_lower(U32 c)
 bool
 is_uni_print(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return is_utf8_print(tmpbuf);
 }
@@ -312,7 +312,7 @@ is_uni_print(U32 c)
 U32
 to_uni_upper(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return to_utf8_upper(tmpbuf);
 }
@@ -320,7 +320,7 @@ to_uni_upper(U32 c)
 U32
 to_uni_title(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return to_utf8_title(tmpbuf);
 }
@@ -328,7 +328,7 @@ to_uni_title(U32 c)
 U32
 to_uni_lower(U32 c)
 {
-    char tmpbuf[10];
+    U8 tmpbuf[10];
     uv_to_utf8(tmpbuf, (UV)c);
     return to_utf8_lower(tmpbuf);
 }
@@ -403,10 +403,10 @@ to_uni_lower_lc(U32 c)
 
 
 bool
-is_utf8_alnum(unsigned char *p)
+is_utf8_alnum(U8 *p)
 {
     if (!PL_utf8_alnum)
-       PL_utf8_alnum = swash_init("utf8", "IsAlnum", &sv_undef, 0, 0);
+       PL_utf8_alnum = swash_init("utf8", "IsAlnum", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_alnum, p);
 /*    return *p == '_' || is_utf8_alpha(p) || is_utf8_digit(p); */
 #ifdef SURPRISINGLY_SLOWER  /* probably because alpha is usually true */
@@ -418,96 +418,96 @@ is_utf8_alnum(unsigned char *p)
 }
 
 bool
-is_utf8_idfirst(unsigned char *p)
+is_utf8_idfirst(U8 *p)
 {
     return *p == '_' || is_utf8_alpha(p);
 }
 
 bool
-is_utf8_alpha(unsigned char *p)
+is_utf8_alpha(U8 *p)
 {
     if (!PL_utf8_alpha)
-       PL_utf8_alpha = swash_init("utf8", "IsAlpha", &sv_undef, 0, 0);
+       PL_utf8_alpha = swash_init("utf8", "IsAlpha", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_alpha, p);
 }
 
 bool
-is_utf8_space(unsigned char *p)
+is_utf8_space(U8 *p)
 {
     if (!PL_utf8_space)
-       PL_utf8_space = swash_init("utf8", "IsSpace", &sv_undef, 0, 0);
+       PL_utf8_space = swash_init("utf8", "IsSpace", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_space, p);
 }
 
 bool
-is_utf8_digit(unsigned char *p)
+is_utf8_digit(U8 *p)
 {
     if (!PL_utf8_digit)
-       PL_utf8_digit = swash_init("utf8", "IsDigit", &sv_undef, 0, 0);
+       PL_utf8_digit = swash_init("utf8", "IsDigit", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_digit, p);
 }
 
 bool
-is_utf8_upper(unsigned char *p)
+is_utf8_upper(U8 *p)
 {
     if (!PL_utf8_upper)
-       PL_utf8_upper = swash_init("utf8", "IsUpper", &sv_undef, 0, 0);
+       PL_utf8_upper = swash_init("utf8", "IsUpper", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_upper, p);
 }
 
 bool
-is_utf8_lower(unsigned char *p)
+is_utf8_lower(U8 *p)
 {
     if (!PL_utf8_lower)
-       PL_utf8_lower = swash_init("utf8", "IsLower", &sv_undef, 0, 0);
+       PL_utf8_lower = swash_init("utf8", "IsLower", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_lower, p);
 }
 
 bool
-is_utf8_print(unsigned char *p)
+is_utf8_print(U8 *p)
 {
     if (!PL_utf8_print)
-       PL_utf8_print = swash_init("utf8", "IsPrint", &sv_undef, 0, 0);
+       PL_utf8_print = swash_init("utf8", "IsPrint", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_print, p);
 }
 
 bool
-is_utf8_mark(unsigned char *p)
+is_utf8_mark(U8 *p)
 {
     if (!PL_utf8_mark)
-       PL_utf8_mark = swash_init("utf8", "IsM", &sv_undef, 0, 0);
+       PL_utf8_mark = swash_init("utf8", "IsM", &PL_sv_undef, 0, 0);
     return swash_fetch(PL_utf8_mark, p);
 }
 
-U32
-to_utf8_upper(unsigned char *p)
+UV
+to_utf8_upper(U8 *p)
 {
     UV uv;
 
     if (!PL_utf8_toupper)
-       PL_utf8_toupper = swash_init("utf8", "ToUpper", &sv_undef, 4, 0);
+       PL_utf8_toupper = swash_init("utf8", "ToUpper", &PL_sv_undef, 4, 0);
     uv = swash_fetch(PL_utf8_toupper, p);
     return uv ? uv : utf8_to_uv(p,0);
 }
 
-U32
-to_utf8_title(unsigned char *p)
+UV
+to_utf8_title(U8 *p)
 {
     UV uv;
 
     if (!PL_utf8_totitle)
-       PL_utf8_totitle = swash_init("utf8", "ToTitle", &sv_undef, 4, 0);
+       PL_utf8_totitle = swash_init("utf8", "ToTitle", &PL_sv_undef, 4, 0);
     uv = swash_fetch(PL_utf8_totitle, p);
     return uv ? uv : utf8_to_uv(p,0);
 }
 
-U32
-to_utf8_lower(unsigned char *p)
+UV
+to_utf8_lower(U8 *p)
 {
     UV uv;
 
     if (!PL_utf8_tolower)
-       PL_utf8_tolower = swash_init("utf8", "ToLower", &sv_undef, 4, 0);
+       PL_utf8_tolower = swash_init("utf8", "ToLower", &PL_sv_undef, 4, 0);
     uv = swash_fetch(PL_utf8_tolower, p);
     return uv ? uv : utf8_to_uv(p,0);
 }
@@ -533,17 +533,17 @@ swash_init(char* pkg, char* name, SV *listsv, I32 minbits, I32 none)
     SAVEI32(PL_hints);
     PL_hints = 0;
     save_re_context();
-    if (curcop == &compiling)  /* XXX ought to be handled by lex_start */
+    if (PL_curcop == &PL_compiling)    /* XXX ought to be handled by lex_start */
        strncpy(tmpbuf, PL_tokenbuf, sizeof tmpbuf);
     if (perl_call_method("SWASHNEW", G_SCALAR))
-       retval = newSVsv(*stack_sp--);    
+       retval = newSVsv(*PL_stack_sp--);    
     else
-       retval = &sv_undef;
+       retval = &PL_sv_undef;
     LEAVE;
     POPSTACK;
-    if (curcop == &compiling) {
+    if (PL_curcop == &PL_compiling) {
        strncpy(PL_tokenbuf, tmpbuf, sizeof tmpbuf);
-       curcop->op_private = PL_hints;
+       PL_curcop->op_private = PL_hints;
     }
     if (!SvROK(retval) || SvTYPE(SvRV(retval)) != SVt_PVHV)
        croak("SWASHNEW didn't return an HV ref");
@@ -551,14 +551,14 @@ swash_init(char* pkg, char* name, SV *listsv, I32 minbits, I32 none)
 }
 
 UV
-swash_fetch(SV *sv, unsigned char *ptr)
+swash_fetch(SV *sv, U8 *ptr)
 {
     HV* hv = (HV*)SvRV(sv);
     U32 klen = UTF8SKIP(ptr) - 1;
     U32 off = ptr[klen] & 127;  /* NB: 64 bit always 0 when len > 1 */
     STRLEN slen;
     STRLEN needents = (klen ? 64 : 128);
-    unsigned char *tmps;
+    U8 *tmps;
     U32 bit;
     SV *retval;
 
@@ -580,10 +580,10 @@ swash_fetch(SV *sv, unsigned char *ptr)
     }
     else {
        /* Try our second-level swatch cache, kept in a hash. */
-       SV** svp = hv_fetch(hv, ptr, klen, FALSE);
+       SV** svp = hv_fetch(hv, (char*)ptr, klen, FALSE);
 
        /* If not cached, generate it via utf8::SWASHGET */
-       if (!svp || !SvPOK(*svp) || !(tmps = SvPV(*svp, slen))) {
+       if (!svp || !SvPOK(*svp) || !(tmps = (U8*)SvPV(*svp, slen))) {
            dSP;
            ENTER;
            SAVETMPS;
@@ -596,18 +596,18 @@ swash_fetch(SV *sv, unsigned char *ptr)
            PUSHs(sv_2mortal(newSViv(needents)));
            PUTBACK;
            if (perl_call_method("SWASHGET", G_SCALAR))
-               retval = newSVsv(*stack_sp--);    
+               retval = newSVsv(*PL_stack_sp--);    
            else
-               retval = &sv_undef;
+               retval = &PL_sv_undef;
            POPSTACK;
            FREETMPS;
            LEAVE;
-           if (curcop == &compiling)
-               curcop->op_private = PL_hints;
+           if (PL_curcop == &PL_compiling)
+               PL_curcop->op_private = PL_hints;
 
-           svp = hv_store(hv, ptr, klen, retval, 0);
+           svp = hv_store(hv, (char*)ptr, klen, retval, 0);
 
-           if (!svp || !(tmps = SvPV(*svp, slen)) || slen < 8)
+           if (!svp || !(tmps = (U8*)SvPV(*svp, slen)) || slen < 8)
                croak("SWASHGET didn't return result of proper length");
        }