adding StringPiece constructor that takes a piece of another StringPiece
authorRafael Sagula <rsagula@fb.com>
Thu, 28 Jun 2012 23:05:21 +0000 (16:05 -0700)
committerTudor Bosman <tudorb@fb.com>
Fri, 13 Jul 2012 23:27:55 +0000 (16:27 -0700)
Summary:
adding what seems to be a missing constructor to StringPiece --
I need to be able to take a piece of another StringPiece. (It's possible
to do that with all sorts of strings already, except StringPiece...)

Test Plan: na -- tested as part of other (dependent) diffs

Reviewed By: delong.j@fb.com

FB internal diff: D508545

folly/Range.h

index e628cd00f523daa3a5f52611510920ff00ef2d61..350183a52f1d960fdada6784dbe2277c2c75f7b4 100644 (file)
@@ -160,6 +160,13 @@ public:
     b_ = str.data() + startFrom;
     e_ = b_ + size;
   }
+  Range(const Range<Iter>& str,
+        size_t startFrom,
+        size_t size) {
+    CHECK_LE(startFrom + size, str.size());
+    b_ = str.b_ + startFrom;
+    e_ = b_ + size;
+  }
   // Works only for Range<const char*>
   /* implicit */ Range(const fbstring& str)
     : b_(str.data()), e_(b_ + str.size()) { }