mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-23 16:21:11 +01:00
tools/rplgen: Move trim to utils.h
This commit is contained in:
parent
1e544d4df5
commit
c412250d48
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(_MSC_VER)
|
||||
@ -125,3 +127,27 @@ align_check(Type value, size_t alignment)
|
||||
#define CHECK_SIZE(Type, Size) \
|
||||
static_assert(sizeof(Type) == Size, \
|
||||
#Type " must be " #Size " bytes")
|
||||
|
||||
// trim from start
|
||||
// Taken from https://stackoverflow.com/a/217605
|
||||
static inline std::string ltrim(std::string s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
return s;
|
||||
}
|
||||
|
||||
// trim from end (in place)
|
||||
static inline std::string rtrim(std::string s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), s.end());
|
||||
return s;
|
||||
}
|
||||
|
||||
// trim from both ends
|
||||
static inline std::string
|
||||
trim(std::string s)
|
||||
{
|
||||
return rtrim(ltrim(s));
|
||||
}
|
||||
|
@ -13,29 +13,6 @@
|
||||
#include <string>
|
||||
#include <zlib.h>
|
||||
|
||||
// trim from start
|
||||
// Taken from https://stackoverflow.com/a/217605
|
||||
static inline void ltrim(std::string &s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
}
|
||||
|
||||
// trim from end (in place)
|
||||
static inline void rtrim(std::string &s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), s.end());
|
||||
}
|
||||
|
||||
// trim from both ends
|
||||
static inline void
|
||||
trim(std::string &s)
|
||||
{
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
enum class ReadMode
|
||||
{
|
||||
INVALID,
|
||||
@ -135,7 +112,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// Trim whitespace
|
||||
trim(line);
|
||||
line = trim(line);
|
||||
|
||||
// Skip blank lines
|
||||
if (line.length() == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user