D-Programming-Language/phobos — pull request #298 by 9rnsr (2011-10-20 17:03:32+00:00)
Title: Cleanup and improve std.format

Points:

- Cleanup template specializations for more maintainable.

- Add `toString(sink)` support.

It is useful when format specifier does not need.

- Add format specifier `%|` for nested range formatting

Previously, In %( xxx %s yyy %) yyy is interpreted as separator implicitly.
But this rule is not good for nested range formatting.
e.g. `[[1,2,3], [4,5,6]]` with `{%(<%(%d%)>, %)}` makes `{<123>, <456}`.

New `%|` format specifiers explicitly divide format strings for element and for separator.
It is used only inside `%(` and `%)`
e.g. `[[1,2,3], [4,5,6]]` with `{%(<%(%d%)>%|, %)}` makes `{<123>, <456>}`.

- Add '%c" specifier for character type formatting

It is already supported for unformatting.
And also, it is necessary for nested range formatting. Now, inside compound format specifier, `%s` runs proper element formatting (do escape for strings, characters, and ranges). It is useful, but in some cases we need a way to avoid escaping. `%c` just do it for characters.

- Issue 5354 - formatValue: range templates introduce 3 bugs related to class & struct cases

Check `toString` is overridden in runtime for class input range object.

- Add toString(sink, ...) support for class and interface types

- Add tests and improvements for reflective formatting.

'Reflective' means:
1. format value.
2. unformat formatted string with *same specifier*.
3. the result value equals to original