Skip to content
Snippets Groups Projects
Commit cae7ce37 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide formatting version of Foam::name() (issue #253)

- 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.
parent 6d5db96a
No related branches found
No related tags found
Loading
Showing
with 266 additions and 32 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment