Skip to content
Snippets Groups Projects
Commit f7438943 authored by Valerio Mariani's avatar Valerio Mariani
Browse files

Added split according to whitespace to StringRef

parent 656cd8b7
No related branches found
No related tags found
No related merge requests found
...@@ -113,6 +113,26 @@ std::vector<StringRef> StringRef::split(char p) const ...@@ -113,6 +113,26 @@ std::vector<StringRef> StringRef::split(char p) const
return result; 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 StringRef::str_no_whitespace() const
{ {
std::string whitespaceless_string; std::string whitespaceless_string;
......
...@@ -147,14 +147,16 @@ public: ...@@ -147,14 +147,16 @@ public:
/// \brief split string into chunks delimited by \p p /// \brief split string into chunks delimited by \p p
std::vector<StringRef> split(char p) const; 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 /// \brief returns a new string with all whitespace removed from
/// this StringRef /// this StringRef
std::string str_no_whitespace() const; std::string str_no_whitespace() const;
private: private:
const char* begin_; const char* begin_;
const char* end_; const char* end_;
}; };
//std::stringstream& operator<<(std::stringstream& stream, const StringRef& strref); //std::stringstream& operator<<(std::stringstream& stream, const StringRef& strref);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment