From d554e4409278791a30906b5de18c7f539d816c9c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 13 Nov 2009 01:24:40 +0000 Subject: Add a new split method to StringRef that puts the substrings in a vector. llvm-svn: 87058 --- llvm/lib/Support/StringExtras.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'llvm/lib/Support/StringExtras.cpp') diff --git a/llvm/lib/Support/StringExtras.cpp b/llvm/lib/Support/StringExtras.cpp index c72f121..05ba34b 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 &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 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); +} -- cgit v1.1