Implement mxs::[l|r]trim(std::string&);

Also remove the non-used implementation in httprequest.cc
This commit is contained in:
Johan Wikman 2018-05-18 16:11:41 +03:00
parent 2e8c19f6be
commit 0f8bf9b6e2
2 changed files with 35 additions and 34 deletions

View File

@ -18,6 +18,7 @@
#include <openssl/sha.h>
#include <zlib.h>
#include <algorithm>
#include <array>
#include <functional>
#include <iterator>
@ -25,10 +26,44 @@
#include <tr1/unordered_map>
#include <maxscale/buffer.h>
#include <maxscale/utils.h>
namespace maxscale
{
/**
* @brief Left trim a string.
*
* @param s The string to be trimmed.
*/
inline void ltrim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
}
/**
* @brief Right trim a string.
*
* @param s The string to be trimmed.
*/
inline void rtrim(std::string &s)
{
s.erase(std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
}
/**
* @brief Trim a string.
*
* @param s The string to be trimmed.
*/
inline void trim(std::string &s)
{
ltrim(s);
rtrim(s);
}
/**
* @class CloserTraits utils.hh <maxscale/utils.hh>
*

View File

@ -27,40 +27,6 @@ using std::deque;
const std::string HttpRequest::HTTP_PREFIX = "http://";
const std::string HttpRequest::HTTPS_PREFIX = "https://";
/** TODO: Move this to a C++ string utility header */
namespace maxscale
{
static inline string& trim(string& str)
{
if (str.length())
{
if (isspace(*str.begin()))
{
string::iterator it = str.begin();
while (it != str.end() && isspace(*it))
{
it++;
}
str.erase(str.begin(), it);
}
if (isspace(*str.rbegin()))
{
string::reverse_iterator it = str.rbegin();
while (it != str.rend() && isspace(*it))
{
it++;
}
str.erase(it.base(), str.end());
}
}
return str;
}
}
static void process_uri(string& uri, std::deque<string>& uri_parts)
{
/** Clean up trailing slashes in requested resource */