[PATCH] D24842: Add StringRef {take, drop} x {_while, _until}

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 14:06:04 PDT 2016


majnemer added inline comments.

================
Comment at: include/llvm/ADT/StringRef.h:499-511
@@ -498,1 +498,15 @@
 
+    template <typename Func>
+    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef take_while(Func F) const {
+      StringRef S(*this);
+      while (!S.empty()) {
+        if (!F(S.front()))
+          break;
+        S = S.drop_front();
+      }
+      return drop_back(S.size());
+    }
+
+    template <typename Func>
+    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef take_until(Func F) const {
+      StringRef S(*this);
----------------
davide wrote:
> Oh, and maybe if you can add a comment at the beginning of each function (e.g. as consume_front() already does) it would be good. 
Can you use function_ref instead?


https://reviews.llvm.org/D24842





More information about the llvm-commits mailing list