diff options
author | Andy Lester <andy@petdance.com> | 2006-05-11 19:21:23 -0500 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-05-12 15:48:43 +0000 |
commit | 64844641e1be28fdf8b7bba9436537339624f40b (patch) | |
tree | 5b2e2be4988f2baeae11add9a83a42f480939771 | |
parent | 931e0695c454f4c18f68d30775151862650cc4d8 (diff) | |
download | perl-64844641e1be28fdf8b7bba9436537339624f40b.tar.gz |
upgrade bytes_to_uni
Message-ID: <20060512052123.GA21648@petdance.com>
p4raw-id: //depot/perl@28180
-rw-r--r-- | embed.fnc | 1 | ||||
-rw-r--r-- | embed.h | 2 | ||||
-rw-r--r-- | pp_pack.c | 23 | ||||
-rw-r--r-- | proto.h | 5 |
4 files changed, 20 insertions, 11 deletions
@@ -1224,6 +1224,7 @@ sR |const char *|get_num |NN const char *ppat|NN I32 *lenptr ns |bool |need_utf8 |NN const char *pat|NN const char *patend ns |char |first_symbol |NN const char *pat|NN const char *patend sR |char * |sv_exp_grow |NN SV *sv|STRLEN needed +sR |char * |bytes_to_uni |NN const U8 *start|STRLEN len|NN char *dest #endif #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT) @@ -1227,6 +1227,7 @@ #define need_utf8 S_need_utf8 #define first_symbol S_first_symbol #define sv_exp_grow S_sv_exp_grow +#define bytes_to_uni S_bytes_to_uni #endif #endif #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT) @@ -3388,6 +3389,7 @@ #define need_utf8 S_need_utf8 #define first_symbol S_first_symbol #define sv_exp_grow(a,b) S_sv_exp_grow(aTHX_ a,b) +#define bytes_to_uni(a,b,c) S_bytes_to_uni(aTHX_ a,b,c) #endif #endif #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT) @@ -702,21 +702,21 @@ next_uni_uu(pTHX_ const char **s, const char *end, I32 *out) return TRUE; } -STATIC void -bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char **dest) { - U8 buffer[UTF8_MAXLEN]; +STATIC char * +S_bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char *dest) { const U8 * const end = start + len; - char *d = *dest; + while (start < end) { + U8 buffer[UTF8_MAXLEN]; const int length = uvuni_to_utf8_flags(buffer, NATIVE_TO_UNI(*start), 0) - buffer; switch(length) { case 1: - *d++ = buffer[0]; + *dest++ = buffer[0]; break; case 2: - *d++ = buffer[0]; - *d++ = buffer[1]; + *dest++ = buffer[0]; + *dest++ = buffer[1]; break; default: Perl_croak(aTHX_ "Perl bug: value %d UTF-8 expands to %d bytes", @@ -724,12 +724,13 @@ bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char **dest) { } start++; } - *dest = d; + return dest; } #define PUSH_BYTES(utf8, cur, buf, len) \ STMT_START { \ - if (utf8) bytes_to_uni(aTHX_ (U8 *) buf, len, &(cur)); \ + if (utf8) \ + (cur) = bytes_to_uni((U8 *) buf, len, (cur)); \ else { \ Copy(buf, cur, len, char); \ (cur) += (len); \ @@ -764,7 +765,7 @@ STMT_START { \ STMT_START { \ if (utf8) { \ const U8 au8 = (byte); \ - bytes_to_uni(aTHX_ &au8, 1, &(s)); \ + (s) = bytes_to_uni(&au8, 1, (s)); \ } else *(U8 *)(s)++ = (byte); \ } STMT_END @@ -3052,7 +3053,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) len+(endb-buffer)*UTF8_EXPAND); end = start+SvLEN(cat); } - bytes_to_uni(aTHX_ buffer, endb-buffer, &cur); + cur = bytes_to_uni(buffer, endb-buffer, cur); } else { if (cur >= end) { *cur = '\0'; @@ -3335,6 +3335,11 @@ STATIC char * S_sv_exp_grow(pTHX_ SV *sv, STRLEN needed) __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); +STATIC char * S_bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char *dest) + __attribute__warn_unused_result__ + __attribute__nonnull__(pTHX_1) + __attribute__nonnull__(pTHX_3); + #endif #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT) |