Limit the number of characters in a string.

@param string $value
@param int $limit Default 50.
@param string $end Default '...'.
@return string
495785
public static function limit(string $value, int $limit = 50, string $end = self::LIMIT_SUFFIX): string
    {
        if (mb_strwidth($value, 'UTF-8') <= $limit) {
            return $value;
        }
        return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
    }
178894
public static function trimPattern($value, array $params)
    {
        if (empty($value) || empty($params['pattern'])) {
            return $value;
        }
        $params['limit'] = Helper::getValue($params['limit'], -1);
        return StringHelper::trimPattern($value, $params['pattern'], $params['limit']);
    }
1251828
public function validate(string $value)
    {
        if (!$value || mb_strlen($value, 'UTF-8') >= $this->minimumLength) {
            return;
        }

        $this->error['minlength.%'] = [$this->minimumLength];
    }
54759
public static function length(string $value, int $min, int $max):bool
    {
        $value = (string)$value;
        $length = Str::length($value);
        return $length >= $min && $length <= $max;
    }
479219
public static function limit($limit) {
        //1. limit(10);
        if ( is_numeric($limit) ) {
            return array(0, $limit);

            //2. limit("10, 50")
        } else if ( is_string( $limit ) ) {
            return explode(',', $limit);
        }
        return $limit;
    }
456256
public function fill($value, $start = null, $end = null)
    {
        $array = $this->getArrayCopy();
        $length = $this->length();

        if ($end <= 0) {
            $end = $length - $end;
        }

        if (is_null($start) === true) {
            $i = $end ?: $length;

            while ($i--) {
                $array[$i] = $value;
            }
        }

        if ($start <= 0) {
            $start = $length - $start;
        }

        $end = $end ?: $length;
        $i = $start;

        while ($i !== $end) {
            $array[$i] = $value;
            $i++;
        }

        return new static($array);
    }
1333504
public static function limitChars($string, $limit = 100, $append = '...'): string
    {
        if (mb_strlen($string) <= $limit) {
            return $string;
        }

        return rtrim(mb_substr($string, 0, $limit)).$append;
    }
412189
public function formatLimit($limit) {
        if ($limit) {
            return sprintf($this->getClause(self::LIMIT), (int) $limit);
        }

        return '';
    }
162570
public static function formatString($string, $limit, $endchars = '...')
    {
        $string = PagSeguroHelper::removeStringExtraSpaces($string);
        return PagSeguroHelper::truncateValue($string, $limit, $endchars);
    }
554851
public static function getWordsWithinCharLimit($sentence, $limit = 150) {
        $str = '';
        $i = 1;

        if(strlen($sentence) < $limit) {
            return $sentence;
        }

        while (strlen($current = self::getWords($sentence, $i++)) < $limit) {
            $str = $current;
        }

        return $str;
    }
164201
public static function limitChars(string $string, int $characters = 100, string $sufix = '...'): string
	{
		return (mb_strlen($string) > $characters) ? trim(mb_substr($string, 0, $characters)) . $sufix : $string;
	}
363983
protected function truncate($string, $limit, $pad = '...', $break = ' ')
    {
        // return with no change if string is shorter than $limit
        if(strlen($string) <= $limit) return $string;

        // is $break present between $limit and the end of the string?
        if(false !== ($breakpoint = strpos($string, $break, $limit))) {
            if($breakpoint < strlen($string) - 1) {
                $string = substr($string, 0, $breakpoint) . $pad;
            }
        }

        return $string;
    }
425891
public function limit(string $sql, int $limit, $offset=FALSE): string
	{
		$sql .= "\nLIMIT {$limit}";

		if (is_numeric($offset))
		{
			$sql .= " OFFSET {$offset}";
		}

		return $sql;
	}
1255592
public function checkEndsWith($value, $end)
    {
        if (!Type::isStringable($value)) {
            return false;
        }

        return Helper::endsWith("$value", $end);
    }
292421
public function buildLimit()
	{
		$string  = 'LIMIT ';
		$string .= ((!empty($this->start)) ? (int)$this->start . ',' : '');
		$string .= ((!empty($this->limit)) ? (int)$this->limit : '18446744073709551615');

		return $string;
	}
464080
public function parseLimit($limit)
    {
        $limitStr = '';
        if (!empty($limit)) {
            $limit = explode(',', $limit);
            if (count($limit) > 1) {
                $limitStr = "(numrow>" . $limit[0] . ") AND (numrow<=" . ($limit[0] + $limit[1]) . ")";
            } else {
                $limitStr = "(numrow>0 AND numrow<=" . $limit[0] . ")";
            }

        }
        return $limitStr ? ' WHERE ' . $limitStr : '';
    }
759616
public function plain($value, $minLength = 0, $maxLength = false, $default = false)
	{
		$value = strip_tags($value);

		return $this->str($value, $minLength, $maxLength, $default);
	}