Commit 837501af authored by aligungr's avatar aligungr

Trim utility added to common

parent 6ed0da6e
......@@ -10,6 +10,7 @@
#include "constants.hpp"
#include <algorithm>
#include <atomic>
#include <cctype>
#include <chrono>
#include <random>
#include <regex>
......@@ -302,3 +303,9 @@ bool utils::IsNumeric(const std::string &str)
{
return !str.empty() && std::all_of(str.begin(), str.end(), [](char c) { return (c >= '0' && c <= '9'); });
}
void utils::Trim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); }));
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end());
}
......@@ -34,6 +34,7 @@ void Sleep(int ms);
bool IsRoot();
bool IsNumeric(const std::string& str);
void AssertNodeName(const std::string &str);
void Trim(std::string& str);
template <typename T>
inline void ClearAndDelete(std::vector<T *> &vector)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment