import std.string; void main() { assert(format("%8s", "foo") == " foo"); assert(format("%8s", "foobar") == " foobar"); assert(format("%8s", "hello") == " hello"); assert(format("%8s", "h\u00e9ll\u00f4") == " h\u00e9ll\u00f4"); // this passes, though it shouldn't: assert(format("%8s", "h\u00e9ll\u00f4") == " h\u00e9ll\u00f4"); } -- In the above, the last assertion fails. One would expect the last two strings, having five characters each, to both be padded in the front by three spaces: however, it appears the byte count is being used for determining the length and not the actual character count, and so the last string is padded by only one space.
> One would expect the last two strings, having five characters each, > to both be padded in the front by three spaces: however, it appears > the byte count is being used for determining the length and not the > actual character count, and so the last string is padded by only one > space. The only relevant documentation I found is: > Width > Specifies the minimum field width. If the width is a *, the next > argument, which must be of type int, is taken as the width. If > the width is negative, it is as if the - was given as a Flags > character. "field width" could be both interpreted as " byte length" and "UTF codepoint count".
I suggest it's codepoint count, as field width is for display purposes.
Fixed dmd 1.032 and 2.016
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル