diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-01-11 19:32:07 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-01-11 19:32:07 +0000 |
commit | 4bfee161f7a97900585aa2d88dc2e41ec655cbfb (patch) | |
tree | 3989c45f2a756331b8b960a417baa1afb718a9fe /mg.c | |
parent | b03c0a3af9d8dc230dbf7f55955fdc7ce65f2403 (diff) | |
parent | 075a4a2b17419f90b0888605cbb91ee4b236f645 (diff) | |
download | perl-4bfee161f7a97900585aa2d88dc2e41ec655cbfb.tar.gz |
Integrate mainline
p4raw-id: //depot/perlio@8406
Diffstat (limited to 'mg.c')
-rw-r--r-- | mg.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -1417,15 +1417,25 @@ Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg) int Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg) { - STRLEN len; - char *tmps = SvPV(sv,len); + STRLEN littlelen; + char *tmps = SvPV(sv, littlelen); + if (DO_UTF8(sv)) { + I32 bigoff = LvTARGOFF(sv); + I32 biglen = LvTARGLEN(sv); + U8 *s, *a, *b; + sv_utf8_upgrade(LvTARG(sv)); - sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len); + /* sv_utf8_upgrade() might have moved and/or resized + * the string to be replaced, we must rediscover it. --jhi */ + s = (U8*)SvPVX(LvTARG(sv)); + a = utf8_hop(s, bigoff); + b = utf8_hop(a, biglen); + sv_insert(LvTARG(sv), a - s, b - a, tmps, littlelen); SvUTF8_on(LvTARG(sv)); } else - sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len); + sv_insert(LvTARG(sv), LvTARGOFF(sv), LvTARGLEN(sv), tmps, littlelen); return 0; } |