Skip to content
Snippets Groups Projects
Commit 1786892b authored by marco's avatar marco
Browse files

added split method to StringRef

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2545 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 67920deb
No related branches found
No related tags found
No related merge requests found
...@@ -93,4 +93,24 @@ std::ostream& operator<<(std::ostream& stream, const StringRef& strref) ...@@ -93,4 +93,24 @@ std::ostream& operator<<(std::ostream& stream, const StringRef& strref)
return stream; return stream;
} }
std::vector<StringRef> StringRef::split(char p) const
{
std::vector<StringRef> result;
const char* s=begin_;
const char* l=begin_;
while (s!=end_) {
if (*s==p) {
if (l!=s) {
result.push_back(StringRef(l, s-l));
}
l=s+1;
}
++s;
}
if (l!=s) {
result.push_back(StringRef(l, s-l));
}
return result;
}
} }
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <iostream> #include <iostream>
#include <ost/base.hh> #include <ost/base.hh>
#include <string.h> #include <string.h>
#include <vector>
#include <ost/module_config.hh> #include <ost/module_config.hh>
...@@ -133,6 +134,8 @@ public: ...@@ -133,6 +134,8 @@ public:
bool empty() const { return begin_==end_; } bool empty() const { return begin_==end_; }
/// \brief split string into chunks delimited by \p p
std::vector<StringRef> split(char p) const;
private: private:
const char* begin_; const char* begin_;
const char* end_; const char* end_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment