Limit the number of characters in a string.

@param  string  $value
@param  int     $limit
@param  string  $end
@return string
966153
public static function limit($value, $limit = 100, $end = '...')
    {
        if (mb_strwidth($value, 'UTF-8') <= $limit) {
            return $value;
        }

        return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
    }
910465
private function parseEndTerm(string $endTerm)
    {
        if ('' === $endTerm) {
            throw new \ErrorException('Parse interval expression');
        }

        $endInclusion = \substr($endTerm, -1);

        if (!\in_array($endInclusion, [self::LEFT, self::RIGHT], true)) {
            throw new \ErrorException('Parse interval expression');
        }

        $isOpen       = $endInclusion === self::RIGHT;
        $endValue     = \substr($endTerm, 0, -1);
        return $this->parseValue($endValue, false, $isOpen);
    }
316247
public function formatLimitOffset($limit, $offset = 0) {
        if ($limit && $offset) {
            return sprintf($this->getClause(self::LIMIT_OFFSET), (int) $limit, (int) $offset);
        }

        return $this->formatLimit($limit);
    }
203173
private function limitLength($value)
    {
        if ($this->stringUtils->strlen($value) > \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT) {
            $value = mb_substr($value, 0, \Dotdigitalgroup\Email\Helper\Data::DM_FIELD_LIMIT);
        }

        return $value;
    }
976892
public function endsWith(string $value): bool
    {
        if ($value === '') {
            return true;
        }

        return (string) $this->takeEnd(self::of($value, $this->encoding)->length()) === $value;
    }
794628
public static function getLimitString($limit)
    {
        if (isset($limit) && !empty($limit)) {
            $limitParts = GeneralUtility::trimExplode(',', $limit);
            if (count($limitParts) === 1) {
                return intval($limitParts[0]);
            }
            if (count($limitParts) === 2) {
                return intval($limitParts[0]) . ',' . intval($limitParts[1]);
            }
        }

        return '';
    }
847525
public function limit($value)
    {
        $property = $this->unions ? 'unionLimit' : 'limit';

        if ($value >= 0) {
            $this->{$property} = $value;
        }

        return $this;
    }
358755
public function setDelimiters($begin, $end)
    {
        $this->beginDelimiter = $begin;

        $this->endDelimiter = $end;

        // for chaining
        return $this;
    }
1241890
protected function parseIdFromHref($limitationValue)
    {
        if (substr($limitationValue['_href'], -1) !== '/') {
            throw new Exceptions\Parser("The '_href' attribute must end with a slash.");
        }

        return '/' . ltrim(parent::parseIdFromHref($limitationValue), '/');
    }
750784
public static function endsWith($string, $end)
    {
        $l = strlen($end);
        if ($l == 0) {
            return true;
        }
        return substr($string, - $l) === $end;
    }
1061074
public function limitWords($string, $limit = false, $end = '...')
    {
        $words = explode(" ", $string);

        if (count($words) <= $limit) {
            return $string;
        }

        $return = [];
        for ($wordCount = 0; $wordCount < $limit; $wordCount++) {
            $return[] = $words[$wordCount];
        }

        $return[] = $end;

        return implode(" ", $return);
    }
191597
protected function lengthValidate($value, $min, $max)
    {
        return $min <= mb_strlen($value) && mb_strlen($value) <= $max;
    }
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;
    }
1325608
private function max($value, $max)
    {
        if (is_string($value)) {
            $value = strlen($value);
        }

        return $value <= $max;
    }
1369995
public function truncate($value, $length, $replace = '...')
    {
        if (!isset($value)) {
            return null;
        }
        
        return strlen($value) <= $length ? $value : substr($value, 0, $length - strlen($replace)) . $replace;
    }
1165624
public function trim($charlist = null, $ends = null)
    {
        switch (true) {
            case is_null($charlist) && ($ends == self::BOTH || is_null($ends)):
                $this->setInternalValue(trim($this->getInternalValue()));
                break;

            case is_null($ends) || $ends == self::BOTH:
                $this->setInternalValue(trim($this->getInternalValue(), $charlist));
                break;

            case !is_null($ends):
                switch (true) {
                    case $ends == self::LEFT:
                        $callback = 'ltrim';
                        break;

                    case $ends == self::RIGHT:
                        $callback = 'rtrim';
                        break;
                }

                if (is_null($charlist)) {
                    $this->setInternalValue(call_user_func($callback, $this->getInternalValue()));
                } else {
                    $this->setInternalValue(call_user_func($callback, $this->getInternalValue(), $charlist));
                }

                break;

        }

        return $this;

    }
739558
public function validate(string $value)
    {
        if (!$value || mb_strlen($value, 'UTF-8') <= $this->maximumLength) {
            return;
        }

        $this->error['maxlength.%'] = [$this->maximumLength];
    }