[Development] Introducing discussion about QStringFormatter

Thiago Macieira thiago.macieira at intel.com
Fri Aug 11 18:10:23 CEST 2017


On sexta-feira, 11 de agosto de 2017 02:01:11 PDT Mårten Nordheim wrote:
> Replacement format
> 
> >>> -----
> >>> 
> >>> The replacement options now have formatting features matching
> >>> QString::arg. The current options (open to change) are:
> >>> 
> >>> - `L` for localization (localize numbers, like in QString::arg)
> >>> - `</>/=` for justification. Left, right and center justification
> >>> 
> >>> - Followed by an optional padding character (excluding 1-9)
> >>> - Followed by field-width
> >>> - e.g. "==16" (pad using '=', centered, field-width 16),
> >>> 
> >>> "<10" (left-justify using spaces, field-width 10),
> >>> ">-3" (right-justify using '-', field-width 3)
> > 
> > Is this inspired by any API? The one I can think of (printf) uses - for
> > left justification and + for right justification. That would make just as
> > much sense in using = for center.
> 
> Yes:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0645r0.html
> https://docs.python.org/3.6/library/string.html#format-specification-mini-la
> nguage
> 
> Although I notice now that they use '^' for centering, and not '='. I
> should probably change to match that.

Python is a compelling reason. A proposed paper for C++2a isn't, since we can 
give feedback and have that change. I don't see anything about left/center/
right in the C# page, while the Rust page says they use < and > for left and 
right, but ^ for center.

Has this ever been validated with people using RTL languages? The < and > 
symbols switch directions when used in RTL. For example:

    const char *fmt =
            "א {<10} ב"
            ;

Can you tell from the pasted text which direction this will justify? I 
intentionally put the semi-colon on a separate line so you can't tell which 
side the tail end of the line is. It's even worse in your text editor -- go 
ahead and copy it to Qt Creator to see how it formats this!

Or is that even a problem? Maybe it's even better this way?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list