pFormat

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

Examples

1 assertEq( pFormat( "%4d", 10 ), "  10" );
2 
3 assertEq( pFormat( "hello %6.4f world %3d ok", 3.141592, 12 ), "hello 3.1415 world  12 ok" );
4 assertEq( pFormat( "hello % 6.3f world %d ok",  3.141592, 12 ), "hello  3.141 world 12 ok" );
5 assertEq( pFormat( "hello % 6.3f world % d ok", -3.141592, 12 ), "hello -3.141 world  12 ok" );
6 assertEq( pFormat( "hello % 6.3f world % 4d ok", -3.141592, 12 ), "hello -3.141 world   12 ok" );
7 assertEq( pFormat( "hello % 6.3f world % d ok", -3.141592, -12 ), "hello -3.141 world -12 ok" );
8 assertEq( pFormat( "hello %+6.3f world %+d ok",  3.141592, 12 ), "hello +3.141 world +12 ok" );
9 
10 assertEq( pFormat( "hello %+13.5e world 0b%b ok", 3.141592, 8 ), "hello  +3.14159e+00 world 0b1000 ok" );
11 assertEq( pFormat( "%10s %s", "hello", "world" ), "     hello world" );
12 
13 assertEq( pFormat( "%2$10s %1$s", "hello", "world" ), "     world hello" );
14 assertEq( pFormat( "%1$10s %1$s", "hello" ), "     hello hello" );
15 assertEq( pFormat( "%1$10s %1$s %3$ 6.3f %2$d", "hello", 14, 2.718281828 ), "     hello hello  2.718 14" );
16 
17 // fmt args without option index starts with first from any place
18 assertEq( pFormat( "%1$10s %1$s %3$ 6.3f %s %d", "hello", 14, 2.718281828 ), "     hello hello  2.718 hello 14" );

Meta