From af7a31fbc157a57d9e2174f05050cb8d9db4efd9 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Mon, 12 Jan 2009 16:06:20 +0000 Subject: [PATCH] Added doxygen info --- Cantera/src/base/PrintCtrl.h | 1 - Cantera/src/base/stringUtils.cpp | 59 +++++++++++++++++++++++--------- Cantera/src/base/stringUtils.h | 46 +++++++++++++++++++++---- 3 files changed, 81 insertions(+), 25 deletions(-) diff --git a/Cantera/src/base/PrintCtrl.h b/Cantera/src/base/PrintCtrl.h index 11e321b33..f82e9a541 100644 --- a/Cantera/src/base/PrintCtrl.h +++ b/Cantera/src/base/PrintCtrl.h @@ -4,7 +4,6 @@ * (see \ref Cantera::PrintCtrl). */ /* - * $Author$ * $Revision$ * $Date$ */ diff --git a/Cantera/src/base/stringUtils.cpp b/Cantera/src/base/stringUtils.cpp index f1b7bdb0a..275f92bd9 100755 --- a/Cantera/src/base/stringUtils.cpp +++ b/Cantera/src/base/stringUtils.cpp @@ -20,21 +20,27 @@ #include "stringUtils.h" #include "ctexceptions.h" #include "global.h" -#include -#include -#include -#include #include "ctml.h" #include +#include +#include +#include +#include + namespace Cantera { - /** - * Convert a floating point number to a std::string using sprintf. + // Convert a double into a c++ string + /* + * This routine doesn't assume a formatting. You + * must supply the formatting + * + * @param x double to be converted + * @param fmt Format to be used (printf style) */ - std::string fp2str(double x, std::string fmt) { + std::string fp2str(const double x, const std::string &fmt) { char buf[64]; int n = SNPRINTF(buf, 63, fmt.c_str(), x); if (n > 0) { @@ -43,7 +49,7 @@ namespace Cantera { } return std::string(" "); } - std::string fp2str(double x) { + std::string fp2str(const double x) { char buf[64]; int n = SNPRINTF(buf, 64, "%g" , x); if (n > 0) { @@ -53,13 +59,12 @@ namespace Cantera { return std::string(" "); } - /** + /* * Convert an integer number to a std::string using sprintf. */ - std::string int2str(int n, std::string fmt) { + std::string int2str(const int n, const std::string &fmt) { char buf[30]; int m = SNPRINTF(buf, 30, fmt.c_str(), n); - //sprintf(buf, fmt.c_str(), n); if (m > 0) { buf[29] = '\0'; return std::string(buf); @@ -67,8 +72,11 @@ namespace Cantera { return std::string(" "); } - - std::string int2str(int n) { + // Convert an int to a string + /* + * @param n int to be converted + */ + std::string int2str(const int n) { char buf[30]; int m = SNPRINTF(buf, 30, "%d", n); if (m > 0) { @@ -85,15 +93,32 @@ namespace Cantera { return lc; } - static int firstChar(std::string s) { + //! Return the position of the first printable + //! character in the string + /*! + * @param s input string + * @return Returns an int representing the first + * printable string. If none returns the + * size of the string. + */ + static int firstChar(const std::string &s) { int i; int n = static_cast(s.size()); - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) { if (s[i] != ' ' && isprint(s[i])) break; + } return i; } - static int lastChar(std::string s) { + //! Return the position of the last printable + //! character in the string + /*! + * @param s input string + * @return Returns an int representing the first + * printable string. If none returns + * -1. + */ + static int lastChar(const std::string &s) { int i; int n = static_cast(s.size()); for (i = n-1; i >= 0; i--) @@ -104,7 +129,7 @@ namespace Cantera { /** * Strip leading and trailing white space. */ - std::string stripws(std::string s) { + std::string stripws(const std::string &s) { int ifirst = firstChar(s); int ilast = lastChar(s); return s.substr(ifirst, ilast - ifirst + 1); diff --git a/Cantera/src/base/stringUtils.h b/Cantera/src/base/stringUtils.h index 07fe29ffd..a8c61f330 100755 --- a/Cantera/src/base/stringUtils.h +++ b/Cantera/src/base/stringUtils.h @@ -1,15 +1,16 @@ /** * @file std::stringUtils.h - * + * Contains declarations for string manipulation functions + * within Cantera. */ // Copyright 2001 California Institute of Technology - #ifndef CT_STRINGUTILS_H #define CT_STRINGUTILS_H #include "ct_defs.h" + #include namespace Cantera { @@ -17,7 +18,15 @@ namespace Cantera { class Phase; class ThermoPhase; - std::string fp2str(double x, std::string fmt); + //! Convert a double into a c++ string + /*! + * This routine doesn't assume a formatting. You + * must supply the formatting + * + * @param x double to be converted + * @param fmt Format to be used (printf style) + */ + std::string fp2str(const double x, const std::string &fmt); //! Convert a double into a c++ string /*! @@ -26,10 +35,33 @@ namespace Cantera { * * @param x double to be converted */ - std::string fp2str(double x); - std::string int2str(int n, std::string fmt); - std::string int2str(int n); - std::string stripws(std::string s); + std::string fp2str(const double x); + + //! Convert an int to a string using a format converter + /*! + * @param n int to be converted + * @param fmt format converter for an int int the printf command + */ + std::string int2str(const int n, const std::string &fmt); + + //! Convert an int to a string + /*! + * @param n int to be converted + */ + std::string int2str(const int n); + + //! Strip the leading and trailing white space + //! from a string + /*! + * The command isprint() is used to determine printable + * characters. + * + * @param s Input string + * @return Returns a copy of the string, stripped + * of leading and trailing white space + */ + std::string stripws(const std::string &s); + std::string stripnonprint(std::string s); std::string lowercase(const std::string &s); void parseCompString(const std::string ss, compositionMap& x);