/** * * * @return MString */ public function substringWithRange(MRange $range) { if ($range->location() < 0) { throw new MIndexOutOfBoundsException($range->location(), 0, $this->length()); } if ($range->location() + $range->length() > $this->length()) { throw new MIndexOutOfBoundsException($range->location() + $range->length(), 0, $this->length()); } return new MString(substr($this->stringValue(), $range->location(), $range->length())); }
/** * * * @return MArray */ public function subarrayWithRange(MRange $range) { return new MArray(array_slice($this->array, $range->location(), $range->length())); }