Adds a ellipses to the right of a string and trims down the size

@param string $string
@param int $max
@param string $ellipses [default='...']
@return string
173378
public static function ellipsizeRight($string, $max, $ellipses = '...') {
		$string = trim($string);
		
		// don't ellipsize if the string is short enough
		if (strlen($string) <= $max) {
			return $string;
		}
		
		// chop at max length
		$string = substr($string, 0, $max);
		
		$chop = strrpos($string, ' ');
		if ($chop !== false)
			$string = substr($string, 0, $chop);
		
		$string = self::removeTrailingPunctuation($string);
		$string .= $ellipses;
		
		return $string;
	}
233623
public static String truncate(String string, int maxBytesLength) {
        byte[] stringBytes = string.getBytes();
        return stringBytes.length > maxBytesLength
                ? new String(stringBytes, 0, maxBytesLength - 1) : string;
    }
657637
function(string, maxLength) {
            if (!string) return string;
            if (maxLength < 1) return string;
            if (string.length <= maxLength) return string;
            if (maxLength == 1) return string.substring(0,1) + '...';

            var midpoint = Math.ceil(string.length / 2);
            var toremove = string.length - maxLength;
            var lstrip = Math.ceil(toremove/2);
            var rstrip = toremove - lstrip;
            return string.substring(0, midpoint-lstrip) + '...' + string.substring(midpoint+rstrip);
        }
949076
public static function generate(string $text = '', ?int $maxLength = null): string
    {
        $text = StripTags::strip($text);
        $text = \strtolower(\iconv('UTF-8', 'ASCII//TRANSLIT', $text));
        $text = \preg_replace('/[^a-z0-9\-\ ]/', '', $text);
        $text = \preg_replace('/[\s\-]+/', '-', $text);
        if (\is_int($maxLength)) {
            $text = \substr($text, 0, $maxLength);
        }
        $text = \rtrim($text, '-');

        return '/'.$text;
    }
773896
public static String maxLengthString(String... strings) {
        String res = "";
        for (String string : strings) {
            if (string.length() > res.length()) {
                res = string;
            }
        }
        return res;
    }
891774
def shorten(string, length=140, ellipsis=None):
    '''
    
    '''
    string = string.strip()

    if len(string) > length:
        if ellipsis is True:
            ellipsis = '…'
        else:
            ellipsis = ellipsis or ''

        L = length - len(ellipsis)

        return ' '.join(string[:L].split(' ')[:-1]).strip(',;:.') + ellipsis

    else:
        return string
258905
public static function createFromCamel($string, $allowSlashes = false)
    {
        $string = trim(preg_replace('/(([A-Z]|[0-9])[^A-Z])/', ' $1', $string));
        return self::create($string, $allowSlashes);
    }
102436
public function parseCommaSeparatedString($string, $maxLength = self::MAX_SEARCH_TERMS_LENGTH)
    {
        $result = null;

        // Check if string is not empty.
        if (strlen(trim($string)) === 0) {
            return null;
        }

        // Lower case for case insensitivity.
        $string = mb_strtolower($string, 'UTF-8');

        // Convert string to array.
        $fields = explode(',', $string);

        // Validate and trim each field.
        $fields = array_map([$this, 'trimAndValidateField'], $fields);

        // Remove null entries.
        $fields = array_filter($fields);

        // Parse back into string.
        $result = implode(',', $fields);

        // Check if max length is exceeded.
        if (strlen($result) > $maxLength) {
            // Shorten to max-length.
            $result = substr($result, 0, $maxLength);

            $fields = explode(',', $result);

            // Remove last element.
            array_pop($fields);

            // Only one search field is provided and exceeds limit.
            if (count($fields) === 0) {
                return null;
            }

            // Parse back into string.
            $result = implode(',', $fields);
        }

        return $result;
    }
1274698
private function getDelimiterRightPosition($string, $offset = 0, $delimiter = ';', $skipInBrackets = false)
    {
        $pos = $this->getDelimiterPos($string, $offset, $delimiter, $skipInBrackets);
        if ($pos === false) {
            return false;
        }

        do {
            $newPos = $this->getDelimiterPos($string, $pos + 1, $delimiter, $skipInBrackets);
            if ($newPos !== false) {
                $pos = $newPos;
            }
        } while ($newPos !== false);

        return $pos;
    }
1234663
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
546365
public function cleanNewlines($string) {
        if ($max = $this->getConfig('maxNewlines')) {
            $string = preg_replace('/\n{' . ($max + 1) . ',}/', str_repeat("\n", $max), $string);
        }

        return trim($string);
    }
623797
public function cropMiddle($text, $maxLength, $delimiter = '...')
    {

        // return text if it doesn't need to be cropped
        if (!$text || strlen($text) <= $maxLength || !substr($text, 0)) {
            return $text;
        }

        $substrLength = floor(($maxLength - strlen($delimiter)) / 2);

        return substr($text, 0, $substrLength).$delimiter.substr($text, -$substrLength);
    }
258118
private function __validateString($string, $minLength = 1, $maxLength = 0)
    {
        if (!is_string($string)) {
            $this->error = 'parameter is not string.';
            return false;
        } else if ($maxLength > 0 && strlen($string) > $maxLength) {
            $this->error = 'parameter is too long. string:' . $string;
            return false;
        } else if (strlen($string) < $minLength) {
            $this->error = 'parameter is too short. string:' . $string;
            return false;
        }
        return true;
    }
901810
public static function cleanupString($string)
    {
        $string = trim($string);
        $string = str_replace(array("\n", "\r", "\0"), '', $string);

        $limit = Config::getInstance()->Tracker['page_maximum_length'];
        $clean = substr($string, 0, $limit);
        return $clean;
    }
1214313
def ellipsis(source, max_length):
    """"""
    if max_length == 0 or len(source) <= max_length:
        return source
    return source[: max(0, max_length - 3)] + "..."
1266582
private static function trimAuthString( $string )
    {
        if ( strlen( $string ) <= self::AUTH_STRING_MAX_LENGTH )
        {
            return $string;
        }
        else
        {
            return substr( $string, 0, self::AUTH_STRING_MAX_LENGTH );
        }
    }
521382
function short(str, max)
			{
				if (str.length > max)
				{
					str = str.substring(0, Math.round(max / 2)) + '...' +
						str.substring(str.length - Math.round(max / 4));
				}
				
				return str;
			}