add ::drop_back() and ::drop_front() methods, which are like pop_front/pop_back on...
authorChris Lattner <sabre@nondot.org>
Tue, 24 Jan 2012 08:58:57 +0000 (08:58 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 24 Jan 2012 08:58:57 +0000 (08:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148791 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringRef.h

index 6c338068962865ed654e71b3b7fad7ea4b0704c1..53ebe6a2af3942dbf2962913e5082b4915f97f37 100644 (file)
@@ -353,6 +353,20 @@ namespace llvm {
       Start = min(Start, Length);
       return StringRef(Data + Start, min(N, Length - Start));
     }
+    
+    /// drop_front - Return a StringRef equal to 'this' but with the first
+    /// elements dropped.
+    StringRef drop_front(unsigned N = 1) const {
+      assert(size() >= N && "Dropping more elements than exist");
+      return substr(N);
+    }
+
+    /// drop_back - Return a StringRef equal to 'this' but with the last
+    /// elements dropped.
+    StringRef drop_back(unsigned N = 1) const {
+      assert(size() >= N && "Dropping more elements than exist");
+      return substr(0, size()-N);
+    }
 
     /// slice - Return a reference to the substring from [Start, End).
     ///