Skip to content

Commit 9bec17d

Browse files
committed
perlguts: Revise pod of UTF8f
This is really about strings. SVs are more conveniently printed using SVf.
1 parent 8b4eae1 commit 9bec17d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pod/perlguts.pod

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,19 +2717,24 @@ whatever the compiler has.
27172717
If you are printing addresses of pointers, use UVxf combined
27182718
with PTR2UV(), do not use %lx or %p.
27192719

2720-
=head2 Formatted Printing of SvPVs
2720+
=head2 Formatted Printing of Strings
27212721

27222722
If you just want the bytes printed in a NUL-terminated string, you can
27232723
just use C<%s> (assuming they are all printables). But if there is a
27242724
possibility the value will be encoded as UTF-8, you should instead use
2725-
the C<UTF8f> format. And as its parameter, use the C<UTF8fARG()> macro.
2726-
Below is a general example using the SV C<err_msg> which is known to
2727-
contain a string and not need magic handling:
2728-
2729-
Perl_croak(aTHX_ "This croaked because: %" UTF8f "\n",
2730-
UTF8fARG(SvUTF8(err_msg),
2731-
SvCUR(err_msg),
2732-
SvPVX(err_msg)));
2725+
the C<UTF8f> format. And as its parameter, use the C<UTF8fARG()> macro:
2726+
2727+
chr * msg;
2728+
2729+
/* U+2018: \xE2\x80\x98 LEFT SINGLE QUOTATION MARK
2730+
U+2019: \xE2\x80\x99 RIGHT SINGLE QUOTATION MARK */
2731+
if (can_utf8)
2732+
msg = "\xE2\x80\x98Uses fancy quotes\xE2\x80\x99";
2733+
else
2734+
msg = "'Uses simple quotes'";
2735+
2736+
Perl_croak(aTHX_ "The message is: %" UTF8f "\n",
2737+
UTF8fARG(can_utf8, strlen(msg), msg));
27332738

27342739
The first parameter to C<UTF8fARG> is a boolean: 1 if the string is in
27352740
UTF-8; 0 if bytes.

0 commit comments

Comments
 (0)