aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT/StringRef.h
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-11-11 05:19:11 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-11-11 05:19:11 +0000
commita8333d3d107df1e0b6bde986ed0532915e154b65 (patch)
tree17d301c68442c9603b044913c8c2974bd5be1d41 /include/llvm/ADT/StringRef.h
parent90a6fd31b73b9e63d2465f19c25e8ee56c7e30db (diff)
downloadexternal_llvm-a8333d3d107df1e0b6bde986ed0532915e154b65.zip
external_llvm-a8333d3d107df1e0b6bde986ed0532915e154b65.tar.gz
external_llvm-a8333d3d107df1e0b6bde986ed0532915e154b65.tar.bz2
Add StringRef::split(StringRef), to complement StringRef::split(char).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86803 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringRef.h')
-rw-r--r--include/llvm/ADT/StringRef.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index a5c43fa..12e2c56 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -289,6 +289,23 @@ namespace llvm {
return std::make_pair(slice(0, Idx), slice(Idx+1, npos));
}
+ /// split - Split into two substrings around the first occurence of a
+ /// separator string.
+ ///
+ /// If \arg Separator is in the string, then the result is a pair (LHS, RHS)
+ /// such that (*this == LHS + Separator + RHS) is true and RHS is
+ /// maximal. If \arg Separator is not in the string, then the result is a
+ /// pair (LHS, RHS) where (*this == LHS) and (RHS == "").
+ ///
+ /// \param Separator - The string to split on.
+ /// \return - The split substrings.
+ std::pair<StringRef, StringRef> split(StringRef Separator) const {
+ size_t Idx = find(Separator);
+ if (Idx == npos)
+ return std::make_pair(*this, StringRef());
+ return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos));
+ }
+
/// rsplit - Split into two substrings around the last occurence of a
/// separator character.
///