From c412250d4833abe40e4211d1290eedf9e22eeb93 Mon Sep 17 00:00:00 2001 From: James Benton Date: Tue, 29 May 2018 09:01:28 +0100 Subject: [PATCH] tools/rplgen: Move trim to utils.h --- tools/common/utils.h | 26 ++++++++++++++++++++++++++ tools/rplgen/rplgen.cpp | 25 +------------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/tools/common/utils.h b/tools/common/utils.h index 971d286c..42c2753e 100644 --- a/tools/common/utils.h +++ b/tools/common/utils.h @@ -1,6 +1,8 @@ #pragma once +#include #include #include +#include #include #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)); +} diff --git a/tools/rplgen/rplgen.cpp b/tools/rplgen/rplgen.cpp index 8431b216..6f15ae1a 100644 --- a/tools/rplgen/rplgen.cpp +++ b/tools/rplgen/rplgen.cpp @@ -13,29 +13,6 @@ #include #include -// 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) {