[llvm-commits] [llvm] r148791 - /llvm/trunk/include/llvm/ADT/StringRef.h
Chris Lattner
sabre at nondot.org
Tue Jan 24 00:58:58 PST 2012
Author: lattner
Date: Tue Jan 24 02:58:57 2012
New Revision: 148791
URL: http://llvm.org/viewvc/llvm-project?rev=148791&view=rev
Log:
add ::drop_back() and ::drop_front() methods, which are like pop_front/pop_back on a vector, but a) aren't destructive to "this", and b) can take a # elements to drop.
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=148791&r1=148790&r2=148791&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Tue Jan 24 02:58:57 2012
@@ -353,6 +353,20 @@
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).
///
More information about the llvm-commits
mailing list