@param string $input
@param int    $length
@param string $string
@param int    $type

@return string
488
public static function pad(string $input, int $length, string $string = ' ', int $type = STR_PAD_RIGHT): string
    {
        $diff = strlen($input) - mb_strlen($input, 'utf-8');

        return str_pad($input, $length + $diff, $string, $type);
    }
772406
protected function short($string, $length = 200)
    {
        if( strlen( $string ) < $length ) {
            return $string;
        }

        return substr( $string, 0, $length ) .'...';
    }
1066260
protected function getAttributeCastForColumnType($type, $length = null)
    {
        switch ($type) {

            case 'bool':
                return AttributeCast::BOOLEAN;

            case 'tinyint':
                if ($length === 1) {
                    return AttributeCast::BOOLEAN;
                }
                return AttributeCast::INTEGER;

            case 'int':
            case 'integer':
            case 'mediumint':
            case 'smallint':
            case 'bigint':
                return AttributeCast::INTEGER;

            case 'dec':
            case 'decimal':
            case 'double':
            case 'float':
            case 'real':
                return AttributeCast::FLOAT;

            case 'varchar':
            case 'char':
            case 'enum':
            case 'text':
            case 'mediumtext':
            case 'longtext':
            case 'tinytext':
            case 'year':
            case 'blob';
            case 'mediumblob';
            case 'longblob';
            case 'binary';
            case 'varbinary';
                return AttributeCast::STRING;

            case 'date':
            case 'datetime':
            case 'time':
            case 'timestamp':
                return AttributeCast::DATE;

            default:
                return $type;
        }
    }
34521
public function string($column, $length = 255)
    {
        return $this->table->addColumn($column, Type::STRING, compact('length'));
    }
438377
public static function raw_hash(
        string $input,
        int $length = \SODIUM_CRYPTO_GENERICHASH_BYTES
    ): string {
        return self::raw_keyed_hash($input, '', $length);
    }
1317404
public static function convert($input = STDIN)
    {
        $stream = fopen('php://temp', 'rw');

        foreach ($_SERVER as $key => $value) {
            if (0 === strpos($key, 'HTTP_')) {
                $key = str_replace('_', '-', strtolower(substr($key, 5)));
                fwrite($stream, "$key: $value\r\n");
            } elseif (in_array($key, ['CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'])) {
                $key = str_replace('_', '-', strtolower($key));
                fwrite($stream, "$key: $value\r\n");
            }
        }

        fwrite($stream, "\r\n");

        stream_copy_to_stream($input, $stream);

        rewind($stream);

        return new StreamedPart($stream);
    }
841180
public static void hasLength(String input, int length, String message) {

    notNull(input, message);
    if (input.trim().length() != length) {
      throw new IllegalArgumentException(message);
    }
  }
1314856
static function substring($input, $start, $length = null) {
		return self::substr($input, $start, $length, "utf-8");
	}
907408
public static function cutStr(string $string, int $length = 9, string $dot = '...', string $char = 'utf8'): string {
		return (mb_strlen($string) > $length) ? mb_substr($string, 0, $length, $char) . $dot : $string;
	}
1097681
public static function substr($string, $start, $length = null)
    {
        return mb_substr($string, $start, $length, self::ENCODING);
    }
818415
public function createTeaser(string $string, int $length = 150): string
    {
        $string = $this->markdownToText($string);
        $suffix = ' ';

        if (strlen($string) > $length) {
            $length = $length - 4;
            $suffix = '... ';
        }

        return substr($string, 0, $length).$suffix;
    }
1248067
public static function random($length = 32, $type = self::RAND_ALL)
    {
        $string = '';
        // todo: make to helper?
        foreach (static::$dictionary as $pos => $item)
        {
            $key = (1 << $pos);
            if ($type >= $key)
            {
                $string .= $item;
                $type   -= $key;
            }
        }

        if (empty($string))
        {
            throw new Exceptions\Blank("Invalid random string type [{$type}].");
        }

        return static::rand($string, $length);
    }
935379
public function read(int $length = 8192): string
    {
        $isAcceptable = $this->predicate;
        while (!$this->inputStream->eof()) {
            $data = $this->inputStream->read($length);
            if ($isAcceptable($data)) {
                return $data;
            }
        }

        return '';
    }
900128
public function char($column, $length = null)
    {
        $length = $length ?: Builder::$defaultStringLength;

        return $this->addColumn('char', $column, compact('length'));
    }
336201
public static function random($type = 'alnum', $length = 16) {
        switch ($type) {
            case 'basic':
                return mt_rand();
                break;

            default:
            case 'alnum':
            case 'numeric':
            case 'nozero':
            case 'alpha':
            case 'distinct':
            case 'hexdec':
                switch ($type) {
                    case 'alpha':
                        $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                        break;

                    default:
                    case 'alnum':
                        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                        break;

                    case 'numeric':
                        $pool = '0123456789';
                        break;

                    case 'nozero':
                        $pool = '123456789';
                        break;

                    case 'distinct':
                        $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
                        break;

                    case 'hexdec':
                        $pool = '0123456789abcdef';
                        break;
                }

                $str = '';
                for ($i = 0; $i < $length; $i++) {
                    $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
                }
                return $str;
                break;

            case 'unique':
                return md5(uniqid(mt_rand()));
                break;

            case 'sha1' :
                return sha1(uniqid(mt_rand(), true));
                break;

            case 'uuid':
                $pool = array('8', '9', 'a', 'b');
                return sprintf('%s-%s-4%s-%s%s-%s', static::random('hexdec', 8), static::random('hexdec', 4), static::random('hexdec', 3), $pool[array_rand($pool)], static::random('hexdec', 3), static::random('hexdec', 12));
                break;
        }
    }
827720
public static function input($length = 0)
    {
        if (self::isCli()) {
            return $length > 0 ? fgets(STDIN, $length) : fgets(STDIN);
        }

        return false;
    }
916765
final protected function fwrite($string, $length = null)
	{
		return is_int($length)
			? fwrite($this->fhandle, $string, $length)
			: fwrite($this->fhandle, $string);
	}