function _strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT) {
        $mb_length = $this->_strlen($input);
        $sb_length = strlen($input);
        $pad_length = $this->_strlen($pad);

        /* Return if we already have the length. */
        if ($mb_length >= $length) {
            return $input;
        }

        /* Shortcut for single byte strings. */
        if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
            return str_pad($input, $length, $pad, $type);
        }

        switch ($type) {
            case STR_PAD_LEFT:
                $left = $length - $mb_length;
                $output = $this->_substr(str_repeat($pad, ceil($left / $pad_length)),
                        0, $left, $this->_charset) . $input;
                break;
            case STR_PAD_BOTH:
                $left = floor(($length - $mb_length) / 2);
                $right = ceil(($length - $mb_length) / 2);
                $output = $this->_substr(str_repeat($pad, ceil($left / $pad_length)),
                        0, $left, $this->_charset) .
                    $input .
                    $this->_substr(str_repeat($pad, ceil($right / $pad_length)),
                        0, $right, $this->_charset);
                break;
            case STR_PAD_RIGHT:
                $right = $length - $mb_length;
                $output = $input .
                    $this->_substr(str_repeat($pad, ceil($right / $pad_length)),
                        0, $right, $this->_charset);
                break;
        }

        return $output;
    }