@@ -356,6 +356,18 @@ private function quote($s)
356356 return '\\Q ' .str_replace ('\\E ' , '\\E \\\\E \\Q ' , $ s ).'\\E ' ;
357357 }
358358
359+ /**
360+ * Converts a string into a regex that matches it at the beginning
361+ *
362+ * @param mixed $s The string or array being replaced.
363+ *
364+ * @return string Returns the string converted.
365+ */
366+ private function regexStartWith ($ s )
367+ {
368+ return '^ ' . $ this ->quote ($ s );
369+ }
370+
359371 /**
360372 * Add a constraint to the query that requires a particular key's value to
361373 * start with the provided value.
@@ -367,7 +379,7 @@ private function quote($s)
367379 */
368380 public function startsWith ($ key , $ value )
369381 {
370- $ this ->addCondition ($ key , '$regex ' , ' ^ ' . $ this ->quote ($ value ));
382+ $ this ->addCondition ($ key , '$regex ' , $ this ->regexStartWith ($ value ));
371383
372384 return $ this ;
373385 }
@@ -1197,6 +1209,25 @@ public function containsAll($key, $values)
11971209 return $ this ;
11981210 }
11991211
1212+ /**
1213+ * Add a constraint to the query that requires a particular key's value to
1214+ * contain each one of the provided list of values starting with the given string.
1215+ *
1216+ * @param string $key The key to check. This key's value must be an array.
1217+ * @param array $values The values that will match as starting string.
1218+ *
1219+ * @return ParseQuery Returns the query, so you can chain this call.
1220+ */
1221+ public function containsAllStartingWith ($ key , $ values )
1222+ {
1223+ $ opts = [];
1224+ for ($ i = 0 ; $ i < count ($ values ); $ i += 1 ) {
1225+ $ opts [] = ['$regex ' => $ this ->regexStartWith ($ values [$ i ])];
1226+ }
1227+
1228+ return $ this ->containsAll ($ key , $ opts );
1229+ }
1230+
12001231 /**
12011232 * Add a constraint for finding objects that contain the given key.
12021233 *
0 commit comments