ENH: improvements to stringOps format and split functions

- split now optionally retains empty substrings.
  Added split on fixed field width.

- Foam::name() now formats directly into string buffer, which a
  removes one layer of copying and also avoids using a non-constexpr
  in the temporary.

STYLE: explicit type narrowing on zero-padded output for ensight
This commit is contained in:
Mark Olesen
2017-11-23 20:17:33 +01:00
parent 6e8586df5d
commit d49929b210
5 changed files with 170 additions and 42 deletions

View File

@ -335,26 +335,29 @@ namespace stringOps
//- Split string into sub-strings at the delimiter character.
// Empty sub-strings are suppressed.
// Empty sub-strings are normally suppressed.
// Behaviour is ill-defined if delim is a NUL character.
template<class StringType>
Foam::SubStrings<StringType> split
(
const StringType& str,
const char delim
const char delim,
const bool keepEmpty = false
);
//- Split string into sub-strings using delimiter string.
// Empty sub-strings are suppressed.
// Empty sub-strings are normally suppressed.
template<class StringType>
Foam::SubStrings<StringType> split
(
const StringType& str,
const std::string& delim
const std::string& delim,
const bool keepEmpty = false
);
//- Split string into sub-strings using any characters in delimiter.
// Empty sub-strings are suppressed.
// Empty sub-strings are normally suppressed.
// Behaviour is ill-defined if delim is an empty string.
template<class StringType>
Foam::SubStrings<StringType> splitAny
(
@ -362,6 +365,14 @@ namespace stringOps
const std::string& delim
);
//- Split string into sub-strings using a fixed field width
// Behaviour is ill-defined if width is zero.
template<class StringType>
Foam::SubStrings<StringType> splitFixed
(
const StringType& str,
const std::string::size_type width
);
//- Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)
// Empty sub-strings are suppressed.