X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=blobdiff_plain;f=src%2Fgromacs%2Futility%2Fstringutil.h;h=004daae3e0353708bfa75d731a5fe6fd2db4b0db;hb=812ab9cc9fc5380bd3ffcae9a10dff8a964fda21;hp=e7e11a6d9ef5c9bf5d1d3a04a7a7dd22add7df77;hpb=aa40ec1fd149313b4402c12dfc499da54abe68d3;p=alexxy%2Fgromacs.git diff --git a/src/gromacs/utility/stringutil.h b/src/gromacs/utility/stringutil.h index e7e11a6d9e..004daae3e0 100644 --- a/src/gromacs/utility/stringutil.h +++ b/src/gromacs/utility/stringutil.h @@ -59,7 +59,7 @@ namespace gmx * * Does not throw. */ -bool inline isNullOrEmpty(const char *str) +static inline bool isNullOrEmpty(const char *str) { return str == NULL || str[0] == '\0'; } @@ -74,12 +74,12 @@ bool inline isNullOrEmpty(const char *str) * Returns true if \p prefix is empty. * Does not throw. */ -bool inline startsWith(const std::string &str, const std::string &prefix) +static inline bool startsWith(const std::string &str, const std::string &prefix) { return str.compare(0, prefix.length(), prefix) == 0; } //! \copydoc startsWith(const std::string &, const std::string &) -bool inline startsWith(const char *str, const char *prefix) +static inline bool startsWith(const char *str, const char *prefix) { return std::strncmp(str, prefix, std::strlen(prefix)) == 0; } @@ -94,7 +94,12 @@ bool inline startsWith(const char *str, const char *prefix) * Returns true if \p suffix is NULL or empty. * Does not throw. */ -bool endsWith(const std::string &str, const char *suffix); +bool endsWith(const char *str, const char *suffix); +//! \copydoc endsWith(const char *, const char *) +static inline bool endsWith(const std::string &str, const char *suffix) +{ + return endsWith(str.c_str(), suffix); +} /*! \brief * Removes a suffix from a string. @@ -335,7 +340,7 @@ class TextLineWrapperSettings * - No maximum line width (only explicit line breaks). * - No indentation. * - No continuation characters. - * - Ignore whitespace after an explicit newline. + * - Do not keep final spaces in input strings. */ TextLineWrapperSettings(); @@ -366,18 +371,18 @@ class TextLineWrapperSettings */ void setFirstLineIndent(int indent) { firstLineIndent_ = indent; } /*! \brief - * Sets whether to remove spaces after an explicit newline. + * Sets whether final spaces in input should be kept. * - * \param[in] bStrip If true, spaces after newline are ignored. + * \param[in] bKeep Whether to keep spaces at the end of the input. * - * If not removed, the space is added to the indentation set with - * setIndent(). - * The default is to not strip such whitespace. + * This means that wrapping a string that ends in spaces also keeps + * those spaces in the output. This allows using the wrapper for + * partial lines where the initial part of the line may end in a space. + * By default, all trailing whitespace is removed. Note that this + * option does not affect spaces before an explicit newline: those are + * always removed. */ - void setStripLeadingWhitespace(bool bStrip) - { - bStripLeadingWhitespace_ = bStrip; - } + void setKeepFinalSpaces(bool bKeep) { bKeepFinalSpaces_ = bKeep; } /*! \brief * Sets a continuation marker for wrapped lines. * @@ -424,8 +429,8 @@ class TextLineWrapperSettings * If -1, \a indent_ is used. */ int firstLineIndent_; - //! Whether to ignore or preserve space after a newline. - bool bStripLeadingWhitespace_; + //! Whether to keep spaces at end of input. + bool bKeepFinalSpaces_; //! If not \c '\0', mark each wrapping point with this character. char continuationChar_; @@ -503,6 +508,9 @@ class TextLineWrapper */ TextLineWrapperSettings &settings() { return settings_; } + //! Returns true if the wrapper would not modify the input string. + bool isTrivial() const; + /*! \brief * Finds the next line to be wrapped. *