/** * * * @return string */ public function firstByte() { if ($this->length() > 0) { $bytes = $this->getBytes(MRange::rangeWithLength(1)); return $bytes[0]; } else { throw new MIndexOutOfBoundsException(); } }
/** * * * @return MArray */ public function subarrayWithRange(MRange $range) { return new MArray(array_slice($this->array, $range->location(), $range->length())); }
/** * * * @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())); }
/** * @internal * * @return void */ public static function _init() { self::$RANGE_NOT_FOUND = MRangeMake(MRange::NOT_FOUND, 0); }