@@ -2717,19 +2717,24 @@ whatever the compiler has.
27172717If you are printing addresses of pointers, use UVxf combined
27182718with PTR2UV(), do not use %lx or %p.
27192719
2720- =head2 Formatted Printing of SvPVs
2720+ =head2 Formatted Printing of Strings
27212721
27222722If you just want the bytes printed in a NUL-terminated string, you can
27232723just use C<%s> (assuming they are all printables). But if there is a
27242724possibility 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
27342739The first parameter to C<UTF8fARG> is a boolean: 1 if the string is in
27352740UTF-8; 0 if bytes.
0 commit comments