[Development] Prettier printing of Unicode strings

Kurt Pattyn pattyn.kurt at gmail.com
Sun Jan 26 13:06:42 CET 2014


On 21 Jan 2014, at 01:05, Thiago Macieira <thiago.macieira at intel.com> wrote:

> I was writing a test today and QtTest told me:
> 
>   Actual   (s) : ?12???
>   Expected (s2): ?12???
> 
> So I went, "duh, ok, it looks the same to me but what's behind those question 
> marks".
> 
> After a bit of changes [https://codereview.qt-project.org/76100], it now 
> prints:
> 
>   Actual   (s) : \u221212\u20A0\uD800\uDC00
>   Expected (s2): \u221212\u20AC\uD800\uDC00
> 
> Which tells me what I got wrong.
> 
> Ok to submit this change then? It will make all toString(QString) print
> 
> - all backslashes as \\
> - the following characters as their escape sequences: \r, \n, \t, \b, \f
> - all other control characters (including 0x7f) as \u00XX
> - all other characters with \uXXXX, including text otherwise readable in the 
>   terminal in the locale

But the number 12 is still displayed as 12. Shouldn’t that also be converted to the \u00XX format (\u0031\u0032)?

> One major advantage of this is that it does not depend on the locale codec 
> being set up or even working, as the previous code did. So we get consistent 
> results even if there's a bug in that.
> 
> Is this ok?
Yes, very okay. It makes QString contents ‘diagnosable'.
> 
> Should I also print quotes as \" ? And should I surround the string with 
> quotes?
I would prefer to output everything in \uXXXX format and to surround the entire output with quotes (to distinguish strings from byte arrays).
> 
> Should I also do the same for QByteArray? Reading hex dumps isn't very nice.
Personally, I don’t have a problem with hex dumps. But, if the byte array contains text data, then it is worth considering.

Cheers,

Kurt
> -- 
> Thiago Macieira - thiago.macieira (AT) intel.com
>  Software Architect - Intel Open Source Technology Center
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development




More information about the Development mailing list