From 498572c67127fde732fcf833a4acd60b77907fe1 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 21 May 2018 10:25:57 +0300 Subject: [PATCH] MXS-1775 Add mxs::[l|r]trimmed_copy(const std::string&) Make it more convenient to get a left-trimmed, right-trimmed or trimmed copy of a string. --- include/maxscale/utils.hh | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/maxscale/utils.hh b/include/maxscale/utils.hh index 15b2eb8b7..d5a316a27 100644 --- a/include/maxscale/utils.hh +++ b/include/maxscale/utils.hh @@ -64,6 +64,49 @@ inline void trim(std::string &s) rtrim(s); } +/** + * @brief Left-trimmed copy of a string. + * + * @param s The string to the trimmed. + * + * @return A left-trimmed copy of the string. + */ +inline std::string ltrimmed_copy(const std::string& original) +{ + std::string s(original); + ltrim(s); + return s; +} + +/** + * @brief Right-trimmed copy of a string. + * + * @param s The string to the trimmed. + * + * @return A right-trimmed copy of the string. + */ +inline std::string rtrimmed_copy(const std::string& original) +{ + std::string s(original); + rtrim(s); + return s; +} + +/** + * @brief Trimmed copy of a string. + * + * @param s The string to the trimmed. + * + * @return A trimmed copy of the string. + */ +inline std::string trimmed_copy(const std::string& original) +{ + std::string s(original); + ltrim(s); + rtrim(s); + return s; +} + /** * @class CloserTraits utils.hh *