/** * 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 testSetLength() { $sb = new StringBuilder(); $sb->setLength(200); $this->assertEquals(200, $sb->capacity()); $this->assertEquals(200, $sb->length()); $sb = new StringBuilder(); $sb->setLength(20); $this->assertEquals(34, $sb->capacity()); $this->assertEquals(20, $sb->length()); }