[Development] Prettier printing of Unicode strings

Matt Broadstone mbroadst at gmail.com
Tue Jan 21 19:31:40 CET 2014


On Mon, Jan 20, 2014 at 7:05 PM, 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
>
> 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?
>
>
+1


> Should I also print quotes as \" ? And should I surround the string with
> quotes?
>
> Should I also do the same for QByteArray? Reading hex dumps isn't very
> nice.
>

I think this would be great as well, but also if there was maybe an io
manipulator to print the hex if you want to look at that as well. Ideally
such a manipulator would print the whole hex, currently the hex printed for
QByteArrays is truncated which in my experience makes it pretty useless in
most cases..

Matt


> --
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140121/5f297727/attachment.html>


More information about the Development mailing list