pFormat

pure
string
pFormat
(
Args...
)
(
string fmt
,
Args args
)

Examples

assertEq( pFormat( "%4d", 10 ), "  10" );

assertEq( pFormat( "hello %6.4f world %3d ok", 3.141592, 12 ), "hello 3.1415 world  12 ok" );
assertEq( pFormat( "hello % 6.3f world %d ok",  3.141592, 12 ), "hello  3.141 world 12 ok" );
assertEq( pFormat( "hello % 6.3f world % d ok", -3.141592, 12 ), "hello -3.141 world  12 ok" );
assertEq( pFormat( "hello % 6.3f world % 4d ok", -3.141592, 12 ), "hello -3.141 world   12 ok" );
assertEq( pFormat( "hello % 6.3f world % d ok", -3.141592, -12 ), "hello -3.141 world -12 ok" );
assertEq( pFormat( "hello %+6.3f world %+d ok",  3.141592, 12 ), "hello +3.141 world +12 ok" );

assertEq( pFormat( "hello %+13.5e world 0b%b ok", 3.141592, 8 ), "hello  +3.14159e+00 world 0b1000 ok" );
assertEq( pFormat( "%10s %s", "hello", "world" ), "     hello world" );

assertEq( pFormat( "%2$10s %1$s", "hello", "world" ), "     world hello" );
assertEq( pFormat( "%1$10s %1$s", "hello" ), "     hello hello" );
assertEq( pFormat( "%1$10s %1$s %3$ 6.3f %2$d", "hello", 14, 2.718281828 ), "     hello hello  2.718 14" );

// fmt args without option index starts with first from any place
assertEq( pFormat( "%1$10s %1$s %3$ 6.3f %s %d", "hello", 14, 2.718281828 ), "     hello hello  2.718 hello 14" );

Meta