[llvm-commits] [llvm] r86803 - /llvm/trunk/include/llvm/ADT/StringRef.h

Daniel Dunbar daniel at zuster.org
Tue Nov 10 21:19:18 PST 2009


Author: ddunbar
Date: Tue Nov 10 23:19:11 2009
New Revision: 86803

URL: http://llvm.org/viewvc/llvm-project?rev=86803&view=rev
Log:
Add StringRef::split(StringRef), to complement StringRef::split(char).

Modified:
    llvm/trunk/include/llvm/ADT/StringRef.h

Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=86803&r1=86802&r2=86803&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Tue Nov 10 23:19:11 2009
@@ -289,6 +289,23 @@
       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.
     ///





More information about the llvm-commits mailing list