From 574c8022b1fdc7312bf9a5af037c8f777b60b6db Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Fri, 22 Mar 2002 04:07:13 +0000 Subject: If Unicode keys are entered to a hash, a bit is turned on. If the bit is on, when the keys are fetched from the hash (%h, each %h, keys %h), the Unicodified versions of the keys are returned if needed. This solution errs on the size of over-Unicodifying, the old solution erred on the side of under-Unicodifying. As long as the hash keys can be a mix of byte and Unicode strings, a perfect fit is hard to come by. p4raw-id: //depot/perl@15407 --- pp.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'pp.c') diff --git a/pp.c b/pp.c index 15bf3515b0..757b4f0984 100644 --- a/pp.c +++ b/pp.c @@ -3686,7 +3686,17 @@ PP(pp_each) EXTEND(SP, 2); if (entry) { - PUSHs(hv_iterkeysv(entry)); /* won't clobber stack_sp */ + SV* sv = hv_iterkeysv(entry); + if (HvUTF8KEYS((SV*)hash) && !DO_UTF8(sv)) { + STRLEN len, i; + char* s = SvPV(sv, len); + for (i = 0; i < len && NATIVE_IS_INVARIANT(s[i]); i++); + if (i < len) { + sv = newSVsv(sv); + sv_utf8_upgrade(sv); + } + } + PUSHs(sv); /* won't clobber stack_sp */ if (gimme == G_ARRAY) { SV *val; PUTBACK; -- cgit v1.2.1