summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/StringExtras.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2009-11-13 01:24:40 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2009-11-13 01:24:40 +0000
commitd554e4409278791a30906b5de18c7f539d816c9c (patch)
tree0e7b53821ce2eb883ef1a66ee2a469a70c8e876b /llvm/lib/Support/StringExtras.cpp
parent46a524c3e8ca4dbe2b3910e3640de8f0a51bb2a4 (diff)
downloadbcm5719-llvm-d554e4409278791a30906b5de18c7f539d816c9c.tar.gz
bcm5719-llvm-d554e4409278791a30906b5de18c7f539d816c9c.zip
Add a new split method to StringRef that puts the substrings in a vector.
llvm-svn: 87058
Diffstat (limited to 'llvm/lib/Support/StringExtras.cpp')
-rw-r--r--llvm/lib/Support/StringExtras.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Support/StringExtras.cpp b/llvm/lib/Support/StringExtras.cpp
index c72f1216534..05ba34b2e7b 100644
--- a/llvm/lib/Support/StringExtras.cpp
+++ b/llvm/lib/Support/StringExtras.cpp
@@ -56,3 +56,22 @@ void llvm::SplitString(const std::string &Source,
S2 = getToken(S, Delimiters);
}
}
+
+void llvm::StringRef::split(std::vector<StringRef> &A,
+ StringRef Separators, unsigned MaxSplit,
+ bool KeepEmpty) const {
+ StringRef rest = *this;
+
+ for (unsigned splits = 0;
+ rest.size() != 0 && (MaxSplit < 0 || splits < MaxSplit);
+ ++splits) {
+ std::pair<llvm::StringRef, llvm::StringRef> p = rest.split(Separators);
+
+ if (p.first.size() != 0 || KeepEmpty)
+ A.push_back(p.first);
+ rest = p.second;
+ }
+
+ if (rest.size() != 0 || KeepEmpty)
+ A.push_back(rest);
+}
OpenPOWER on IntegriCloud