diff --git a/src/utils.h b/src/utils.h index 38f91cfc66..45b751bd2e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -43,6 +43,15 @@ namespace utils { /*! Compare two string while ignoring whitespace * +\verbatim embed:rst + +.. versionadded:: TBD + +This function compares two strings while skipping over any kind of whitespace +(blank, tab, newline, carriage return, etc.). + +\endverbatim + * * \param text1 the first text to be compared * \param text2 the second text to be compared * \return true if the non-whitespace part of the two strings matches, false if not */ @@ -51,6 +60,14 @@ namespace utils { /*! Compress whitespace in a string * +\verbatim embed:rst + +.. versionadded:: TBD + +This function compresses whitespace in a string to just a single blank. + +\endverbatim + * * \param text the text to be compressed * \return string with whitespace compressed to single blanks */ @@ -77,11 +94,22 @@ namespace utils { /*! Create string with last command and optionally pointing to arg with error * - * This function is a helper function for error messages. It creates +\verbatim embed:rst + +.. versionadded:: TBD + +This function is a helper function for error messages. It creates extra output +in error messages. It will produce either two or three lines: the original last +input line *before* variable substitutions, the corresponding pre-processed command +(only when different) and one or more '^' characters pointing to the faulty argument +as indicated by the *failed* argument. Any whitespace in the lines with the command +output are compressed to a single blank by calling :cpp:func:`strcompress()` + +\endverbatim * * \param input pointer to the Input class instance (for access to last command args) - * \param faile index of the faulty argument (-1 to point to the command itself) - * \return string with two lines: the pre-processed command and a '^' pointing to the faulty argument */ + * \param failed index of the faulty argument (-1 to point to the command itself) + * \return string with two or three lines to follow error messages */ std::string point_to_error(Input *input, int failed); /*! Internal function handling the argument list for logmesg(). */ @@ -111,6 +139,36 @@ namespace utils { void logmesg(LAMMPS *lmp, const std::string &mesg); + /*! Internal function handling the argument list for print(). */ + + void fmtargs_print(FILE *fp, fmt::string_view format, fmt::format_args args); + + /*! Write formatted message to file + * +\verbatim embed:rst + +.. versionadded:: TBD + +\endverbatim + * + * This function implements a version of fprintf() that uses {fmt} formatting + * + * \param fp stdio FILE pointer + * \param format format string of message to be printed + * \param args arguments to format string */ + + template void print(FILE *fp, const std::string &format, Args &&...args) + { + fmtargs_print(fp, format, fmt::make_format_args(args...)); + } + + /*! \overload + * + * \param fp stdio FILE pointer + * \param mesg string with message to be printed */ + + void print(FILE *fp, const std::string &mesg); + /*! Return text redirecting the user to a specific paragraph in the manual * * The LAMMPS manual contains detailed explanations for errors and