summaryrefslogtreecommitdiff
path: root/src/core/common/Utils.hpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 00:02:54 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 00:02:54 +0100
commit2659b4595d809cbd69a77e5ff7e2fc08d225f065 (patch)
treebe6a39fcf7d7070494076832a2e652ea1aa4c91e /src/core/common/Utils.hpp
parent974afd3fdc54380a43445a180263fb162e1ff2c0 (diff)
Tidied OsxmlEventParser up, implemented correct whitespace handling, started to write unit tests for the osxml parser
Diffstat (limited to 'src/core/common/Utils.hpp')
-rw-r--r--src/core/common/Utils.hpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp
index 16a9136..8361973 100644
--- a/src/core/common/Utils.hpp
+++ b/src/core/common/Utils.hpp
@@ -120,8 +120,25 @@ public:
template <class T, class Filter>
static std::pair<size_t, size_t> trim(const T &s, Filter f)
{
+ return trim(s, s.size(), f);
+ }
+
+ /**
+ * 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 len is the number of elements in the container.
+ * @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, size_t len, Filter f)
+ {
size_t start = 0;
- for (size_t i = 0; i < s.size(); i++) {
+ for (size_t i = 0; i < len; i++) {
if (!f(s[i])) {
start = i;
break;
@@ -129,7 +146,7 @@ public:
}
size_t end = 0;
- for (ssize_t i = s.size() - 1; i >= static_cast<ssize_t>(start); i--) {
+ for (ssize_t i = len - 1; i >= static_cast<ssize_t>(start); i--) {
if (!f(s[i])) {
end = i + 1;
break;