summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-01-03 14:23:17 +0000
committerNicholas Clark <nick@ccl4.org>2008-01-03 14:23:17 +0000
commit289d3c6afee2ee5aaa9c3c2e0498d35fffce0173 (patch)
tree422c59be5582b0d39d4bf2532cb6166acac71983 /hv.h
parente04fc022e49988f16aeec759a25e58028d32e7d5 (diff)
downloadperl-289d3c6afee2ee5aaa9c3c2e0498d35fffce0173.tar.gz
Add HeUTF8() to complement HePV() and then immediately suggest that
newSVhek(HeKEY_hek(he) is probably what you wanted all along. p4raw-id: //depot/perl@32812
Diffstat (limited to 'hv.h')
-rw-r--r--hv.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/hv.h b/hv.h
index 8d4088e8a5..3be32e675e 100644
--- a/hv.h
+++ b/hv.h
@@ -198,7 +198,18 @@ variable C<PL_na>, though this is rather less efficient than using a local
variable. Remember though, that hash keys in perl are free to contain
embedded nulls, so using C<strlen()> or similar is not a good way to find
the length of hash keys. This is very similar to the C<SvPV()> macro
-described elsewhere in this document.
+described elsewhere in this document. See also C<HeUTF8>.
+
+If you are using C<HePV> to get values to pass to C<newSVpvn()> to create a
+new SV, you should consider using C<newSVhek(HeKEY_hek(he))> as it is more
+efficient.
+
+=for apidoc Am|char*|HeUTF8|HE* he|STRLEN len
+Returns whether the C<char *> value returned by C<HePV> is encoded in UTF-8,
+doing any necessary dereferencing of possibly C<SV*> keys. The value returned
+will be 0 or non-0, not necesarily 1 (or even a value with any low bits set),
+so B<do not> blindly assign this to a C<bool> variable, as C<bool> may be a
+typedef for C<char>.
=for apidoc Am|SV*|HeSVKEY|HE* he
Returns the key as an C<SV*>, or C<NULL> if the hash entry does not
@@ -305,6 +316,9 @@ C<SV*>.
#define HePV(he,lp) ((HeKLEN(he) == HEf_SVKEY) ? \
SvPV(HeKEY_sv(he),lp) : \
((lp = HeKLEN(he)), HeKEY(he)))
+#define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
+ SvUTF8(HeKEY_sv(he)) : \
+ (U32)HeKUTF8(he))
#define HeSVKEY(he) ((HeKEY(he) && \
HeKLEN(he) == HEf_SVKEY) ? \