original_string: public function truncate($length, $substring = '') {
  		if ($this->length() <= $length) {
  			return new Text($this->string, $this->encoding);
  		}
  
  		$substrLen = mb_strlen($substring, $this->encoding);
  
  		if ($this->length() + $substrLen > $length) {
  			$length -= $substrLen;
  		}
  
  		return $this->substring(0, $length)->append($substring);
  	}
code: public function truncate($length, $substring = '') {
  		if ($this->length() <= $length) {
  			return new Text($this->string, $this->encoding);
  		}
  
  		$substrLen = mb_strlen($substring, $this->encoding);
  
  		if ($this->length() + $substrLen > $length) {
  			$length -= $substrLen;
  		}
  
  		return $this->substring(0, $length)->append($substring);
  	}
code_tokens: public function truncate ( $ length , $ substring = '' ) { if ( $ this -> length ( ) <= $ length ) { return new Text ( $ this -> string , $ this -> encoding ) ; } $ substrLen = mb_strlen ( $ substring , $ this -> encoding ) ; if ( $ this -> length ( ) + $ substrLen > $ length ) { $ length -= $ substrLen ; } return $ this -> substring ( 0 , $ length ) -> append ( $ substring ) ; }
docstring: Truncates the string with a substring and ensures it doesn't exceed the given length
  
  @param int $length
  @param string $substring
  @return Text
docstring_tokens: Truncates the string with a substring and ensures it doesn t exceed the given length