[OTLayout] Add start/end to apply_string()

No functional change.
diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh
index 56b3a4f..1d4bd5a 100644
--- a/src/hb-ot-layout-gpos-table.hh
+++ b/src/hb-ot-layout-gpos-table.hh
@@ -1461,19 +1461,24 @@
 
   static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index);
 
-  inline bool apply_string (hb_apply_context_t *c, const hb_set_digest_t *digest) const
+  inline bool apply_string (hb_apply_context_t *c,
+			    unsigned int start,
+			    unsigned int end,
+			    const hb_set_digest_t *digest) const
   {
     bool ret = false;
 
-    if (unlikely (!c->buffer->len || !c->lookup_mask))
+    end = MIN (end, c->buffer->len);
+
+    if (unlikely (start >= end || !c->lookup_mask))
       return false;
 
     c->set_recurse_func (apply_recurse_func);
     c->set_lookup (*this);
 
-    c->buffer->idx = 0;
+    c->buffer->idx = start;
 
-    while (c->buffer->idx < c->buffer->len)
+    while (c->buffer->idx < end)
     {
       if (digest->may_have (c->buffer->cur().codepoint) &&
 	  (c->buffer->cur().mask & c->lookup_mask) &&
diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh
index 4844709..3982cd0 100644
--- a/src/hb-ot-layout-gsub-table.hh
+++ b/src/hb-ot-layout-gsub-table.hh
@@ -1247,11 +1247,15 @@
   }
 
   static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index);
-  inline bool apply_string (hb_apply_context_t *c, const hb_set_digest_t *digest) const
+  inline bool apply_string (hb_apply_context_t *c,
+			    unsigned int start,
+			    unsigned int end,
+			    const hb_set_digest_t *digest) const
   {
     bool ret = false;
+    end = MIN (end, c->buffer->len);
 
-    if (unlikely (!c->buffer->len || !c->lookup_mask))
+    if (unlikely (start >= end || !c->lookup_mask))
       return false;
 
     c->set_recurse_func (apply_recurse_func);
@@ -1261,9 +1265,10 @@
     {
       /* in/out forward substitution */
       c->buffer->clear_output ();
-      c->buffer->idx = 0;
 
-      while (c->buffer->idx < c->buffer->len)
+      c->buffer->idx = start;
+
+      while (c->buffer->idx < end)
       {
 	if (digest->may_have (c->buffer->cur().codepoint) &&
 	    (c->buffer->cur().mask & c->lookup_mask) &&
@@ -1272,14 +1277,15 @@
 	else
 	  c->buffer->next_glyph ();
       }
+
       if (ret)
-	c->buffer->swap_buffers ();
+        c->buffer->swap_buffers ();
     }
     else
     {
       /* in-place backward substitution */
       c->buffer->remove_output ();
-      c->buffer->idx = c->buffer->len - 1;
+      c->buffer->idx = end - 1;
       do
       {
 	if (digest->may_have (c->buffer->cur().codepoint) &&
@@ -1288,9 +1294,8 @@
 	  ret = true;
 	else
 	  c->buffer->idx--;
-
       }
-      while ((int) c->buffer->idx >= 0);
+      while ((int) c->buffer->idx >= (int) start);
     }
 
     return ret;
diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh
index b016542..b3bb371 100644
--- a/src/hb-ot-layout-private.hh
+++ b/src/hb-ot-layout-private.hh
@@ -223,6 +223,8 @@
 hb_ot_layout_substitute_lookup (hb_font_t    *font,
 				hb_buffer_t  *buffer,
 				unsigned int  lookup_index,
+				unsigned int  start,
+				unsigned int  end,
 				hb_mask_t     mask,
 				hb_bool_t     auto_zwj);
 
@@ -246,6 +248,8 @@
 hb_ot_layout_position_lookup (hb_font_t    *font,
 			      hb_buffer_t  *buffer,
 			      unsigned int  lookup_index,
+			      unsigned int  start,
+			      unsigned int  end,
 			      hb_mask_t     mask,
 			      hb_bool_t     auto_zwj);
 
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index a9c02aa..abfcb2c 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -724,6 +724,8 @@
 hb_ot_layout_substitute_lookup (hb_font_t    *font,
 				hb_buffer_t  *buffer,
 				unsigned int  lookup_index,
+				unsigned int  start,
+				unsigned int  end,
 				hb_mask_t     mask,
 				hb_bool_t     auto_zwj)
 {
@@ -733,7 +735,7 @@
 
   const OT::SubstLookup& l = hb_ot_layout_from_face (font->face)->gsub->get_lookup (lookup_index);
 
-  return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gsub_digests[lookup_index]);
+  return l.apply_string (&c, start, end, &hb_ot_layout_from_face (font->face)->gsub_digests[lookup_index]);
 }
 
 void
@@ -775,6 +777,8 @@
 hb_ot_layout_position_lookup (hb_font_t    *font,
 			      hb_buffer_t  *buffer,
 			      unsigned int  lookup_index,
+			      unsigned int  start,
+			      unsigned int  end,
 			      hb_mask_t     mask,
 			      hb_bool_t     auto_zwj)
 {
@@ -784,7 +788,7 @@
 
   const OT::PosLookup& l = hb_ot_layout_from_face (font->face)->gpos->get_lookup (lookup_index);
 
-  return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gpos_digests[lookup_index]);
+  return l.apply_string (&c, start, end, &hb_ot_layout_from_face (font->face)->gpos_digests[lookup_index]);
 }
 
 void
diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc
index dd26afc..df96a09 100644
--- a/src/hb-ot-map.cc
+++ b/src/hb-ot-map.cc
@@ -116,12 +116,14 @@
       {
         case 0:
 	  hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index,
+					  0, (unsigned int) -1,
 					  lookups[table_index][i].mask,
 					  lookups[table_index][i].auto_zwj);
 	  break;
 
 	case 1:
 	  hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index,
+					0, (unsigned int) -1,
 					lookups[table_index][i].mask,
 					lookups[table_index][i].auto_zwj);
 	  break;
diff --git a/src/hb-ot-shape-complex-arabic-fallback.hh b/src/hb-ot-shape-complex-arabic-fallback.hh
index 996e40e..8469ad8 100644
--- a/src/hb-ot-shape-complex-arabic-fallback.hh
+++ b/src/hb-ot-shape-complex-arabic-fallback.hh
@@ -245,9 +245,10 @@
 			    hb_buffer_t *buffer)
 {
   for (unsigned int i = 0; i < ARABIC_NUM_FALLBACK_FEATURES; i++)
-    if (fallback_plan->lookup_array[i]) {
+    if (fallback_plan->lookup_array[i])
+    {
       OT::hb_apply_context_t c (0, font, buffer, fallback_plan->mask_array[i], true/*auto_zwj*/);
-      fallback_plan->lookup_array[i]->apply_string (&c, &fallback_plan->digest_array[i]);
+      fallback_plan->lookup_array[i]->apply_string (&c, 0, (unsigned int) -1, &fallback_plan->digest_array[i]);
     }
 }