MXS-2208 Move trim-functions from maxscale to maxbase

log.h now includes string.hh, which is conceptually wrong, but
log.h will shortly disappear and be superceded by log.hh.
This commit is contained in:
Johan Wikman
2018-12-05 14:54:41 +02:00
parent 60cbeaf287
commit 1b5b789342
25 changed files with 352 additions and 339 deletions

View File

@ -20,7 +20,7 @@
#include <unistd.h>
#include <maxbase/log.h>
#include <maxbase/string.h>
#include <maxbase/string.hh>
MXS_BEGIN_DECLS

View File

@ -117,41 +117,6 @@ void gw_sha1_2_str(const uint8_t* in, int in_len, const uint8_t* in2, int
int gw_getsockerrno(int fd);
char* create_hex_sha1_sha1_passwd(char* passwd);
/**
* Trim leading whitespace from a string.
*
* @param str String to trim.
* @return @c str
*
* @note If there is leading whitespace, the string is moved so that
* the returned pointer is always the same as the one given as
* argument.
*/
char* trim_leading(char* str);
/**
* Trim trailing whitespace from a string.
*
* @param str String to trim.
* @return @c str
*
* @note The returned pointer is always the same the one given as
* argument.
*/
char* trim_trailing(char* str);
/**
* Trim leading and trailing whitespace from a string.
*
* @param str String to trim.
* @return @c str
*
* @note If there is leading whitespace, the string is moved so that
* the returned pointer is always the same the one given as
* argument.
*/
char* trim(char* str);
void replace_whitespace(char* str);
char* squeeze_whitespace(char* str);
bool strip_escape_chars(char*);

View File

@ -34,86 +34,6 @@
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);
}
/**
* @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;
}
/**
* Tokenize a string
*