Pad both sides

@param int $length
@param string $character

@return self
966859
public function uniPad(int $length, string $character = ' '): self
    {
        return $this->pad($length, $character, self::PAD_BOTH);
    }
88115
public function substring($start, $length = null)
    {

        if ($length == null) {
            $substring = substr($this->value, $start);
        } else {
            $substring = substr($this->value, $start, $length);
        }

        $this->value = $substring;

        return $this;


    }
394959
public function setLength($length)
    {
        if (intval($length) < 0) {
            throw new \LengthException(sprintf('Invalid length: %d', $length));
        }

        $this->length = intval($length);

        return $this;
    }
544472
public static function decToHex($dec, $length = 0)
    {
        $gmp = gmp_init($dec, 10);
        $hex = gmp_strval($gmp, 16);

        return self::pad($hex, $length);
    }
948276
protected function pad($string, $len)
    {
        $strlen = $this->strlen($string);
        if ($strlen > $len) return $string;

        $pad = $len - $strlen;
        return $string . str_pad('', $pad, ' ');
    }
503069
public function appendPosition($length)
    {
        $this->dataPosition = (int) $this->dataPosition;
        $this->dataPosition += (int) $length;
        return $this;
    }
234523
public function resize($size, $char = "\0")
  {
    $chars = ($size - $this->count());

    if($chars < 0)
    {
      $this->string = substr($this->string, 0, $chars);
    }
    elseif($chars > 0)
    {
      $this->string = str_pad($this->string, $size, strval($char));
    }

    return $this;
  }
538588
public function pad($pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT)
        {
            $string = $this->get();
            $value = str_pad($string, $pad_length, $pad_string, $pad_type);
            $this->update($value);
            return $this;
        }
958150
public function appendSpace($length)
    {
        $paddingLength = (int) $length;
        $this->message = $this->message . str_pad('', $paddingLength, ' ');

        return $this;
    }
1289388
public function setLength(int $length) : self
    {
        $this->minLength = $length;
        $this->maxLength = $length;

        return $this;
    }
632307
public function cutEnd($length) {
		$rawString = mb_substr($this->rawString, 0, $this->length() - $length, $this->charset);

		return new static($rawString, $this->charset);
	}
853236
public function padLeft($length, $padString)
    {
        if (!$this->isNumber($length)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$length',
                'integer'
            ]);
        }

        if (!$this->isString($padString)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$padString',
                'string'
            ]);
        }

        $this->val(str_pad($this->val(), $length, $padString, STR_PAD_LEFT));

        return $this;
    }
1335996
public function padLeft($num, self $char){
		
		if(!\is_numeric($num)){
			throw new \InvalidArgumentException('$num is not an int');
		}
		
		return new static($char->repeat($num)->_Value . $this->_Value, $this->_Encoding);
		
	}
703323
public function setCharAt( $position, $character )
	{
		if( $position <= $this->count() && $position >= 0 )
			$this->buffer[$position] = $character;
		return $this->toString();
	}
150361
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);
	}
501863
public static String pad(String rawString, int length, char padChar)
  {
    String padded = rawString;
    String padFiller = null;

    if (padded.length() == length)
    {
      return padded;
    }

    if (padded.length() < length)
    {
      //
      // Keep a zero string that is big enough to pad the
      // largest field that we have, then to pad each field
      // we just append this string to the field and then
      // substr to the desired size.
      //
      StringBuffer buff = new StringBuffer(length);

      for (int i = buff.length(); i < length; i++)
      {
        buff.append(padChar);
      }
      padFiller = buff.toString();

      padded = rawString + padFiller;
      return padded.substring(0, length);

    }
    else
    {
      return padded.substring(0, length);
    }
  }
1311613
public function truncate($length)
    {
        $this->_text = StringHelper::truncate($this->_text, $length);
        
        return $this;
    }