From 3c1071f27f81b6dfd8d73d825ae7de3c747da907 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 2 Dec 2000 19:49:35 +0000 Subject: (Retracted by #7978, too shaky yet.) Subject: Re: utf8 in hash keys, implementor missing Message-ID: <20001202194935.A25673@pembro33.pmb.ox.ac.uk> The first step at UTF-8 hash keys. p4raw-id: //depot/perl@7977 --- hv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'hv.c') diff --git a/hv.c b/hv.c index 8a43a19eb5..51c8d0a1a7 100644 --- a/hv.c +++ b/hv.c @@ -245,6 +245,9 @@ Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, register U32 hash) if (!hv) return 0; + if (SvUTF8((SV*)hv) && !SvUTF8(keysv)) + sv_utf8_upgrade(keysv); + if (SvRMAGICAL(hv)) { if (mg_find((SV*)hv,'P')) { dTHR; @@ -463,6 +466,20 @@ Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, register U32 hash) return 0; xhv = (XPVHV*)SvANY(hv); + + if (SvUTF8((SV*)hv) && !SvUTF8(keysv)) + sv_utf8_upgrade(keysv); + else if (SvUTF8(keysv) && !SvUTF8((SV*)hv)) { /* Upgrade hash */ + SvUTF8_on((SV*)hv); + /* XXX Need to save iterator to prevent weird things during "each" */ + (void)hv_iterinit(hv); + while (entry = hv_iternext(hv)) { + if (HeKLEN(entry) != HEf_SVKEY) /* Upgrade to SV key */ + HeSVKEY_set(entry, newSVpvn(HeKEY(entry), HeKLEN(entry))); + sv_utf8_upgrade(HeKEY_sv(entry)); + } + } + if (SvMAGICAL(hv)) { dTHR; bool needs_copy; -- cgit v1.2.1