Pascal Viandier wrote:
However, for the common case of 0-padding, we might support a simpler format such as C's %05s (width 5, zero-padded) in addition.
Note that ofr these purposes it's probably better to have the padding specified in the format string, i.e.:
FormatString ('%05s', x)
rather than
FormatString ('%0s', x : 5)
as in the latter case the padding would be done before InternalFormatString, so it couldn't tell the padding spaces (which it should convert to 0's) from leading spaces in x (if x is a string) which should not be converted.
Of course, we can't stop the user from writing x : 5, but we can provide padding in the format string, so it's up to the user which one he uses.
At first glance I would agree with this. But it introduces a possibility of conflicts between the format string and the width indicator of the parameter. What should do FormatString ('%05s', x : 8)
First pad x to 8 chars with spaces, then pad the result to 5 chars with 0's. Since the first gives already 8 chars (minimum), the latter won't do anything, i.e. it's equivalent to just '%s'.
or worse FormatString ('%08s', x : 5)
Pad x to 5 chars with spaces, then to 8 chars with zeros. This actually has a non-trivial effect (maybe useful to someone).
There isn't actually much choice what to do about : padding, unless we implement it much differently (and much more complicated, it seems). If users use both forms of padding at the same time, they should know what they're doing (tm). :-)
This has also the inconvenience of limiting the padding capability to '0' unless we allow '%x8s' to pad with 'x' like in some accounting receipts or cheques.
As I wrote before, the possibility of padding with an arbitrary character seems interesting. I just think we need a special indicator for it, as otherwise any character with a different meaning could not be used for padding. So e.g. %&x8s with my completely random choice of & could work for the receipt.
An other interesting example would be FormatString ('%-', '-':80 ); which makes a string of 80 '-'. I know there are many other ways to this but I find this one nice and easy.
Also interesting, though (see above), this won't work with : padding, but with format string padding, such as:
FormatString ('%&-80s', '')
(The second argument can be the empty string actually, but '-' also works, of course.)
Frank