diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2002-03-22 04:07:13 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-03-22 04:07:13 +0000 |
commit | 574c8022b1fdc7312bf9a5af037c8f777b60b6db (patch) | |
tree | 06b4317b44c20a0a8683822193a3359385f3c9bf /doop.c | |
parent | 3fbcfac442ddabdaab668242ba16ca26c5edd56c (diff) | |
download | perl-574c8022b1fdc7312bf9a5af037c8f777b60b6db.tar.gz |
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
Diffstat (limited to 'doop.c')
-rw-r--r-- | doop.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -1336,8 +1336,19 @@ Perl_do_kv(pTHX) PUTBACK; /* hv_iternext and hv_iterval might clobber stack_sp */ while ((entry = hv_iternext(keys))) { SPAGAIN; - if (dokeys) - XPUSHs(hv_iterkeysv(entry)); /* won't clobber stack_sp */ + if (dokeys) { + SV* sv = hv_iterkeysv(entry); + if (HvUTF8KEYS((SV*)hv) && !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); + } + } + XPUSHs(sv); /* won't clobber stack_sp */ + } if (dovalues) { PUTBACK; tmpstr = realhv ? |