summaryrefslogtreecommitdiff
path: root/src/core/common/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/common/Utils.cpp')
-rw-r--r--src/core/common/Utils.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp
index 4005143..3739c61 100644
--- a/src/core/common/Utils.cpp
+++ b/src/core/common/Utils.cpp
@@ -21,6 +21,7 @@
#include <string>
#include "Utils.hpp"
+#include "WhitespaceHandler.hpp"
namespace ousia {
@@ -87,5 +88,29 @@ std::string Utils::extractFileExtension(const std::string &filename)
}
return std::string{};
}
+
+std::string Utils::trim(const std::string &s)
+{
+ std::pair<size_t, size_t> bounds = trim(s, Utils::isWhitespace);
+ return s.substr(bounds.first, bounds.second - bounds.first);
+}
+
+std::string Utils::collapse(const std::string &s)
+{
+ CollapsingWhitespaceHandler h;
+ appendToWhitespaceHandler(h, s, 0);
+ return h.toString();
+}
+
+bool Utils::startsWith(const std::string &s, const std::string &prefix)
+{
+ return prefix.size() <= s.size() && s.substr(0, prefix.size()) == prefix;
+}
+
+bool Utils::endsWith(const std::string &s, const std::string &suffix)
+{
+ return suffix.size() <= s.size() &&
+ s.substr(s.size() - suffix.size(), suffix.size()) == suffix;
+}
}