I've been thinking a bit about how to succinctly produce quoted strings of various formats from pike code, and sprintf("%O", s) used to be fairly close to the answer in 7.6, but used octal escapes with two " marks afterward, if the following character was a number, which got fixed in 7.7 via \uXXXX quotes instead. In 7.7, however, now any occurrence of \n gets turned into the five characters '\', 'n', '"', '\n', '"', which again is just as bad as 7.6 was with octal numbers.
I don't care much for the argument that %O is only intended for debug purposes, as long as there is no equally succinct way of producing the kind of quoted strings for log files, consumption of other languages and the like you typically want quoted strings for in the first place; the functionality ought to be somewhere (not necessarily sprintf %O, even though I would personally find that awfully convenient), and it should be terse.
Opinions, ideas, wishes? Can Locale.Charset easily be abused to produce a codec that would work in 7.6 and 7.7 alike and turn \n and similar C shorthands into two-byte sequences and escape above-ASCII as \uXXXX?
%q was implemented for that reason according to the discussion from january to march 2006 with subject "sprintf %O"
checking today, i notice that %q does only handle strings. this is not what i would have expected. to work as intended %q would need to handle any type, just like %O does.
greetings, martin.
I don't care much for the argument that %O is only intended for debug purposes, as long as there is no equally succinct way of producing the
From the sprintf() documentation:
*! @value 'O' *! Any value, debug style. Do not rely on the exact formatting; *! how the result looks can vary depending on locale, phase of *! the moon or anything else the _sprintf method implementor *! wanted for debugging.
kind of quoted strings for log files, consumption of other languages and the like you typically want quoted strings for in the first place; the functionality ought to be somewhere (not necessarily sprintf %O, even though I would personally find that awfully convenient), and it should be terse.
Same source:
*! @value 'q' *! Quoted string. Escapes all control and non-8-bit characters, *! as well as the quote characters @tt{'\'@} and @tt{'"'@}.
Thanks. It didn't occur to me looking further than site refdocs, which of course cover only 7.6 for natural reasons.
that's useful, but not what some of us were looking for.
when we had this discussion last time the consensus seemed to ask for a %O style format that can be used for logging purposes, and has a reliable output format without special characters like newlines.
maybe use %Q for that?
greetings, martin.
pike-devel@lists.lysator.liu.se