diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2009-11-13 01:24:40 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2009-11-13 01:24:40 +0000 |
commit | 5ccac247263ab62975f3b72421fc783f10ccf5f6 (patch) | |
tree | ee40658b6a24ab4b4cf1a96d3a6a4d02dc567a30 /lib/Support/StringExtras.cpp | |
parent | c1a07be185d50fb3201782e4c832356f612480fb (diff) |
Add a new split method to StringRef that puts the substrings in a vector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@87058 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/StringExtras.cpp')
-rw-r--r-- | lib/Support/StringExtras.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp index c72f121653..05ba34b2e7 100644 --- a/lib/Support/StringExtras.cpp +++ b/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); +} |