diff --git a/modules/base/src/string_ref.cc b/modules/base/src/string_ref.cc index 6a1d622541a331df3c2d8e4fa9d33bc4f3442cd6..46705256523ef07bd300cf016b19bc9f94056ed7 100644 --- a/modules/base/src/string_ref.cc +++ b/modules/base/src/string_ref.cc @@ -113,6 +113,26 @@ std::vector<StringRef> StringRef::split(char p) const return result; } +std::vector<StringRef> StringRef::split() const +{ + std::vector<StringRef> result; + const char* s=begin_; + const char* l=begin_; + while (s!=end_) { + if (isspace(*s)) { + 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; +} + std::string StringRef::str_no_whitespace() const { std::string whitespaceless_string; diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh index d72a27a8532897810cde97e6009464bfefd31d1f..48ab841055192522f2068cc91a4df79c97ac20c1 100644 --- a/modules/base/src/string_ref.hh +++ b/modules/base/src/string_ref.hh @@ -147,14 +147,16 @@ public: /// \brief split string into chunks delimited by \p p std::vector<StringRef> split(char p) const; + + /// \brief split string into chunks delimited by whitespace + std::vector<StringRef> split() const; /// \brief returns a new string with all whitespace removed from /// this StringRef std::string str_no_whitespace() const; private: const char* begin_; - const char* end_; - + const char* end_; }; //std::stringstream& operator<<(std::stringstream& stream, const StringRef& strref);