aboutsummaryrefslogtreecommitdiffstats
path: root/include
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
commit5ccac247263ab62975f3b72421fc783f10ccf5f6 (patch)
treeee40658b6a24ab4b4cf1a96d3a6a4d02dc567a30 /include
parentc1a07be185d50fb3201782e4c832356f612480fb (diff)
downloadexternal_llvm-5ccac247263ab62975f3b72421fc783f10ccf5f6.zip
external_llvm-5ccac247263ab62975f3b72421fc783f10ccf5f6.tar.gz
external_llvm-5ccac247263ab62975f3b72421fc783f10ccf5f6.tar.bz2
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 'include')
-rw-r--r--include/llvm/ADT/StringRef.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index b07dcc1..6ccb37d 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -15,6 +15,14 @@
#include <cstring>
#include <string>
+namespace std {
+ template<typename _Tp>
+ class allocator;
+
+ template<typename _Tp, typename _Alloc>
+ class vector;
+}
+
namespace llvm {
/// StringRef - Represent a constant reference to a string, i.e. a character
@@ -314,6 +322,25 @@ namespace llvm {
return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos));
}
+ /// split - Split into substrings around the occurences of a separator
+ /// string.
+ ///
+ /// Each substring is stored in \arg A. If \arg MaxSplit is >= 0, at most
+ /// \arg MaxSplit splits are done and consequently <= \arg MaxSplit
+ /// elements are added to A.
+ /// If \arg KeepEmpty is false, empty strings are not added to \arg A. They
+ /// still count when considering \arg MaxSplit
+ /// An useful invariant is that
+ /// Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true
+ ///
+ /// \param A - Where to put the substrings.
+ /// \param Separator - The string to split on.
+ /// \param MaxSplit - The maximum number of times the string is split.
+ /// \parm KeepEmpty - True if empty substring should be added.
+ void split(std::vector<StringRef, std::allocator<StringRef> > &A,
+ StringRef Separator, unsigned MaxSplit = -1,
+ bool KeepEmpty = true) const;
+
/// rsplit - Split into two substrings around the last occurence of a
/// separator character.
///