handmade/include/trim.h
Bubblegumdrop 46b2ed80ae Initial commit.
Another nuke! This time, trying to do a client <-> server thing.

Also a bit of messing with Lua.
2022-01-02 19:28:16 -05:00

37 lines
638 B
C++

#pragma once
/* https://stackoverflow.com/a/217605 */
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
// trim from start
static inline
std::string&
ltrim (std::string& s)
{
s.erase (s.begin (), std::find_if (s.begin (), s.end (), std::not1 (std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
static inline
std::string&
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 ());
return s;
}
// trim from both ends
static inline
std::string&
trim (std::string& s)
{
return ltrim (rtrim (s));
}