- there are some cases in which the C-style sprintf is much more
convenient, albeit problematic for buffer overwrites.
Provide a formatting version of Foam::name() for language
primitives that is buffer-safe.
Returns a Foam::word, so that further output will be unquoted, but
without any checking that the characters are indeed entirely valid
word characters.
Example use,
i = 1234;
s = Foam::name("%08d", i);
produces '00001234'
Alternative using string streams:
std::ostringstream buf;
buf.fill('0');
buf << setw(8) << i;
s = buf.str();
Note that the format specification can also be slightly more complex:
Foam::name("output%08d.vtk", i);
Foam::name("timing=%.2fs", time);
It remains the caller's responsibility to ensure that the format mask
is valid.