From 1786892bb8208678a969f6c80ddd365611816478 Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Thu, 8 Jul 2010 08:30:47 +0000
Subject: [PATCH] added split method to StringRef

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2545 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/base/src/string_ref.cc | 20 ++++++++++++++++++++
 modules/base/src/string_ref.hh |  3 +++
 2 files changed, 23 insertions(+)

diff --git a/modules/base/src/string_ref.cc b/modules/base/src/string_ref.cc
index 547c38dee..af19d7b8f 100644
--- a/modules/base/src/string_ref.cc
+++ b/modules/base/src/string_ref.cc
@@ -93,4 +93,24 @@ std::ostream& operator<<(std::ostream& stream, const StringRef& strref)
   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;
+}
+
 }
diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh
index b1a38dcf0..c6150b922 100644
--- a/modules/base/src/string_ref.hh
+++ b/modules/base/src/string_ref.hh
@@ -27,6 +27,7 @@
 #include <iostream>
 #include <ost/base.hh>
 #include <string.h>
+#include <vector>
 #include <ost/module_config.hh>
 
 
@@ -133,6 +134,8 @@ public:
   
   bool empty() const { return begin_==end_; }
 
+  /// \brief split string into chunks delimited by \p p
+  std::vector<StringRef> split(char p) const;
 private:
   const char* begin_;
   const char* end_;  
-- 
GitLab