/** * Returns the length of the {@code String} representation * of this {@code StringJoiner}. Note that if * no add methods have been called, then the length of the {@code String} * representation (either {@code prefix + suffix} or {@code emptyValue}) * will be returned. The value should be equivalent to * {@code toString().length()}. * * @return int * the length of the current value of {@code StringJoiner} */ public function length() { // Remember that we never actually append the suffix unless we return // the full (present) value or some sub-string or length of it, so that // we can add on more if we need to. return $this->value !== null ? $this->value->length() + $this->suffix->length() : $this->emptyValue->length(); }
public function testSubstringTwoParams() { $string = $this->string->substring(0, $this->string->length()); $this->assertEquals(spl_object_hash($string), spl_object_hash($this->string)); $string = $this->string->substring(1, $this->string->length()); $this->assertEquals("est String", $string->getOriginalValue()); $string = $this->string->substring(1, 4); $this->assertEquals("est", $string->getOriginalValue()); $string = $this->string->subSequence(1, 4); $this->assertEquals("est", $string->getOriginalValue()); $string = $this->string->substring($this->string->length(), $this->string->length()); $this->assertEquals("", $string->getOriginalValue()); $string = $this->string->substring(0, 0); $this->assertEquals("", $string->getOriginalValue()); }