Fills up a text buffer with '*' to consume by default 72 chars.

@param  string $buffer
@param  int    $length
@return string
962282
public static function formatWithAsterisk(string $buffer, int $length = 72) : string
    {
        return $buffer . str_repeat('*', $length - strlen($buffer)) . PHP_EOL;
    }
138383
public static function truncate($text, $length = 100)
    {
        return (self::length($text) > $length)
            ? rtrim(self::substr($text, 0, $length - 3)) . '...'
            : $text;
    }
1243071
public function max(int $length) : Text
    {
        return $this->pipe(
            self::predicate(
                function (string $value) use ($length) : bool {
                    return strlen($value) <= $length;
                },
                'more than ' . self::characterf($length)
            )
        );
    }
1250446
public function calculate(string $buffer): int
    {
        $bufferLength = \strlen($buffer);

        $mask = (((1 << ($this->bitLength - 1)) - 1) << 1) | 1;
        $highBit = 1 << ($this->bitLength - 1);

        $crc = $this->init;

        for ($iterator = 0; $iterator < $bufferLength; ++$iterator) {
            $character = \ord($buffer[$iterator]);
            if ($this->reverseIn) {
                $character = $this->binaryReverse($character, 8);
            }

            for ($j = 0x80; $j; $j >>= 1) {
                $bit = $crc & $highBit;
                $crc <<= 1;

                if ($character & $j) {
                    $bit ^= $highBit;
                }

                if ($bit) {
                    $crc ^= $this->poly;
                }
            }
        }

        if ($this->reverseOut) {
            $crc = $this->binaryReverse($crc, $this->bitLength);
        }

        $crc ^= $this->xorOut;

        return $crc & $mask;
    }
1083447
static public function EncodeLength($length)
    {
        self::CheckMessageLength($length);

        $string = "";
        do{
            $digit = $length % 0x80;
            $length = $length >> 7;
            // if there are more digits to encode, set the top bit of this digit
            if ( $length > 0 ) $digit = ($digit | 0x80);
            $string .= chr($digit);
        } while ( $length > 0 );

        return $string;
    }
832556
public function readLine($length = 1024)
    {
        if ($this->ensureContent() === false) {
            return false;
        }

        $line = '';
        while ($this->ensureContent()) {
            $char = $this->readByte();

            if ($char === "\n") {
                break;
            }

            if ($char === "\r") {
                if ($this->getByte() === "\n") {
                    $this->addOffset(1);
                }
                break;
            }

            $line .= $char;

            if (\strlen($line) >= $length) {
                break;
            }
        }

        return $line;
    }
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;
	}
1039219
public function seekAndRead($length)
    {
        $this->stream->seek($this->offset + $this->position);
        if ($this->limit !== -1) {
            $length = min($length, $this->limit - $this->position);
            if ($length <= 0) {
                return '';
            }
        }
        return $this->stream->read($length);
    }
58141
public function getRandomString(int $length = 64): string
    {
        $chars  = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()';
        $random = '';

        for ($i = 0; $i < $length; $i++) {
            $random .= substr($chars, random_int(0, strlen($chars) - 1), 1);
        }

        return $random;
    }
708526
private function _generateCSRFToken($length=32)
    {
        $randUtils = new RandomUtils();
        $randToken = $randUtils->getBytes($length, true);
        return base64_encode($randToken);
    }
288073
public function getWriteBuffer(int $length, string $append = ''): Promise
    {
        if (strlen($append)) {
            $this->append = $append;
            $this->append_after = $length - strlen($append);
        }

        return new \Amp\Success($this);
    }
1267613
public static function subDescription(string $text, int $length): string
    {
        return mb_strlen($text, 'utf-8') > $length ? substr($text, 0, $length - 3) . '...' : $text;
    }
564452
public static function readShortInt(&$buffer)
    {
        $tmp = unpack('n', $buffer);
        $buffer = substr($buffer, 2);
        return array_pop($tmp);
    }
1151225
public function truncateText($text = null, $length = 0) {
		$result = '';
		if (empty($text)) {
			return $result;
		}

		$text = (string)$text;
		$length = (int)$length;
		if ($length <= 0) {
			$length = 50;
		}

		if (($text === h($text)) && (mb_strlen($text) <= $length)) {
			return $text;
		}

		$truncateOpt = $this->_getOptionsForElem('truncateText.truncateOpt');
		$tuncatedText = $this->Text->truncate($text, $length, $truncateOpt);
		if ($tuncatedText === $text) {
			return $tuncatedText;
		}

		$result = $this->Html->div('collapse-text-truncated', $tuncatedText);
		$result .= $this->Html->div(
			'collapse-text-original',
			$text . $this->_getOptionsForElem('truncateText.collapseLink')
		);
		$result = $this->Html->div('collapse-text-expanded', $result);

		return $result;
	}
279204
public static function truncate($str, $length, $postFix = '...')
    {
        if (strlen($str) <= $length) {
            return $str;
        }

        return substr($str, 0, ($length - strlen($postFix))) . $postFix;
    }
1286274
public static function stringTrim(string $string, int $length): string
    {
        if ($length<16) return $string;
        if (strlen($string)>$length) {
            $str_head = substr($string, 0, $length-10);
            $str_tail = substr($string, -7, 7);
            return $str_head.'...'.$str_tail;
        }
        return $string;
    }
514294
protected function _createToken($length = 32)
	{
		static $chars = '0123456789abcdef';
		$max = strlen($chars) - 1;
		$token = '';
		$name = session_name();

		for ($i = 0; $i < $length; ++$i)
		{
			$token .= $chars[(rand(0, $max))];
		}

		return md5($token . $name);
	}