diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-14 23:50:11 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-14 23:50:11 +0100 |
commit | 295783320ea3855a14123f9cea163f8f5f689e07 (patch) | |
tree | f3f536f36910cce7ef8f30846b10fcb93f32b646 /src/core/common/Whitespace.hpp | |
parent | ce5ab62b564476dfacba33507f1541166fda2bfb (diff) |
Moved some of the whitespace functionality back to Utils
Diffstat (limited to 'src/core/common/Whitespace.hpp')
-rw-r--r-- | src/core/common/Whitespace.hpp | 62 |
1 files changed, 1 insertions, 61 deletions
diff --git a/src/core/common/Whitespace.hpp b/src/core/common/Whitespace.hpp index 1e9f36a..72a2291 100644 --- a/src/core/common/Whitespace.hpp +++ b/src/core/common/Whitespace.hpp @@ -19,8 +19,7 @@ /** * @file Whitespace.hpp * - * Contains the WhitespaceMode enum used in various places, as well es functions - * for trimming and collapsing whitespaces. + * Contains the WhitespaceMode enum used in various places. * * @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de) */ @@ -55,65 +54,6 @@ enum class WhitespaceMode { COLLAPSE }; -/** - * Collection of functions for trimming or collapsing whitespace. - */ -class Whitespace { - /** - * Removes whitespace at the beginning and the end of the given string. - * - * @param s is the string that should be trimmed. - * @return a trimmed copy of s. - */ - static std::string trim(const std::string &s); - - /** - * Trims the given string or vector of chars by returning the start and end - * index. - * - * @param s is the container that should be trimmed. - * @param f is a function that returns true for values that should be - * removed. - * @return start and end index. Note that "end" points at the character - * beyond the end, thus "end" minus "start" - */ - template <class T, class Filter> - static std::pair<size_t, size_t> trim(const T &s, Filter f) - { - size_t start = 0; - for (size_t i = 0; i < s.size(); i++) { - if (!f(s[i])) { - start = i; - break; - } - } - - size_t end = 0; - for (ssize_t i = s.size() - 1; i >= static_cast<ssize_t>(start); i--) { - if (!f(s[i])) { - end = i + 1; - break; - } - } - - if (end < start) { - start = 0; - end = 0; - } - - return std::pair<size_t, size_t>{start, end}; - } - - /** - * Collapses the whitespaces in the given string (trims the string and - * replaces all whitespace characters by a single one). - * - * @param s is the string in which the whitespace should be collapsed. - * @return a copy of s with collapsed whitespace. - */ - static std::string collapse(const std::string &s); -}; - } #endif /* _OUSIA_WHITESPACE_HPP_ */ |