From 0e0f05cfcb72e9d679a6681b9fcabd732856f942 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 11 Oct 2014 16:31:39 +0200 Subject: added support for custom tokens in dislaychannel --- libcore/helpers.c | 18 ++++++++++++++++++ libcore/helpers.h | 4 ++++ 2 files changed, 22 insertions(+) (limited to 'libcore') diff --git a/libcore/helpers.c b/libcore/helpers.c index b4b507a..f24f6e7 100644 --- a/libcore/helpers.c +++ b/libcore/helpers.c @@ -121,6 +121,24 @@ bool FirstFileInFolder(string &path, string &extension, string &fileName) { return false; } +// trim from start +string <rim(string &s) { + s.erase(s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun(isspace)))); + return s; +} + +// trim from end +string &rtrim(string &s) { + s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), s.end()); + return s; +} + +// trim from both ends +string &trim(string &s) { + return ltrim(rtrim(s)); +} + + // split: receives a char delimiter; returns a vector of strings // By default ignores repeated delimiters, unless argument rep == 1. vector& splitstring::split(char delim, int rep) { diff --git a/libcore/helpers.h b/libcore/helpers.h index 74ddf94..884738d 100644 --- a/libcore/helpers.h +++ b/libcore/helpers.h @@ -16,6 +16,10 @@ bool FileExists(const string &path, const string &name, const string &ext); bool FolderExists(const string &path); bool FirstFileInFolder(string &path, string &extension, string &fileName); +string <rim(string &s); +string &rtrim(string &s); +string &trim(string &s); + class splitstring : public std::string { std::vector flds; public: -- cgit v1.2.3