Beispiel #1
0
 /**
  * Sets the length of the character sequence.
  * The sequence is changed to a new character sequence
  * whose length is specified by the argument. For every nonnegative
  * index <i>k</i> less than {@code newLength}, the character at
  * index <i>k</i> in the new character sequence is the same as the
  * character at index <i>k</i> in the old sequence if <i>k</i> is less
  * than the length of the old character sequence; otherwise, it is the
  * null character {@code '\0'}.
  *
  * In other words, if the {@code newLength} argument is less than
  * the current length, the length is changed to the specified length.
  * <p>
  * If the {@code newLength} argument is greater than or equal
  * to the current length, sufficient null characters
  * ({@code '\0'}) are appended so that
  * length becomes the {@code newLength} argument.
  * <p>
  * The {@code newLength} argument must be greater than or equal
  * to {@code 0}.
  *
  * @param      $newLength   int
  *             the new length
  * @throws     StringIndexOutOfBoundsException  if the
  *               {@code newLength} argument is negative.
  */
 public function setLength($newLength)
 {
     if ($newLength < 0) {
         throw new StringIndexOutOfBoundsException($newLength);
     }
     $this->ensureCapacityInternal($newLength);
     if ($this->length() < $newLength) {
         Arrays::fillFromTo($this->value, $this->length(), $newLength, "");
     }
     $this->count = $newLength;
 }
Beispiel #2
0
 public function testFillFromTo()
 {
     $str = "";
     Arrays::fillFromTo($str, 0, 200, "");
     $this->assertEquals(200, mb_strlen($str));
 }