From 510da5d8de7928a80aa35220976967860591fae2 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 28 Mar 2019 20:55:49 +0100 Subject: [PATCH] helpers: add trim methodes for left and right trim Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/5e1b9aaa4d4c41c057539a22358469ef53d1056f Author: Thilo Graf Date: 2019-03-28 (Thu, 28 Mar 2019) --- src/system/helpers.cpp | 12 ++++++++++++ src/system/helpers.h | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 3037a7a81..e101cc8b9 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -613,6 +613,18 @@ std::string trim(std::string &str, const std::string &trimChars /*= " \n\r\t"*/) return result.erase(0, result.find_first_not_of(trimChars)); } +std::string ltrim(std::string& str, const std::string& trimChars) +{ + str.erase(0, str.find_first_not_of(trimChars)); + return str; +} + +std::string rtrim(std::string& str, const std::string& trimChars) +{ + str.erase(str.find_last_not_of(trimChars) + 1); + return str; +} + std::string cutString(const std::string str, int msgFont, const int width) { Font *msgFont_ = g_Font[msgFont]; diff --git a/src/system/helpers.h b/src/system/helpers.h index 6feed86a8..e5d8cd3a8 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -71,7 +71,9 @@ std::string getBaseName(std::string &path); std::string getFileName(std::string &file); std::string getFileExt(std::string &file); std::string getNowTimeStr(const char* format); -std::string trim(std::string &str, const std::string &trimChars = " \n\r\t"); +std::string trim(std::string& str, const std::string& trimChars = " \n\r\t"); +std::string ltrim(std::string& str, const std::string& trimChars = " \n\r\t"); +std::string rtrim(std::string& str, const std::string& trimChars = " \n\r\t"); std::string cutString(const std::string str, int msgFont, const int width); std::string strftime(const char *format, const struct tm *tm); std::string strftime(const char *format, time_t when, bool gm = false);