Truncates a string to the number of characters specified.

@param string $value
@param array $params params:

- length: count of output characters (minus 3, because point).

@return string
540207
public static function truncate($value, array $params)
    {
        if (empty($params['length']) || !is_numeric($params['length'])) {
            $params['length'] = 4;
        }

        return StringHelper::truncate($value, (int)$params['length']);
    }
924361
public static function truncateValue($string, $limit, $endchars = '...')
    {

        if (!is_array($string) && !is_object($string)) {
            $stringLength = strlen($string);
            $endcharsLength = strlen($endchars);

            if ($stringLength > (int) $limit) {
                $cut = (int) ($limit - $endcharsLength);
                $string = substr($string, 0, $cut) . $endchars;
            }
        }
        return $string;
    }
230316
private function check($value, $params) {

		if(true === is_string($value)) {

			if(true === $params[0]) {
				return filter_var($value, \FILTER_VALIDATE_URL) !== false;
			}
 			
 			$value = preg_replace('/^http(s):\/\//i', '', $value);
 			$value = 'http://' . $value;

 			return filter_var($value, \FILTER_VALIDATE_URL) !== false;
 		}

 		return false;
	}
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;
    }
866444
private String setParamsters(String value, final Object[] params) {
		for (int i = 0; i < params.length; i++) {
			value = value.replaceAll("\\{" + i + "\\}", params[i].toString());
		}
		return value;
	}
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']);
    }
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;
    }
251389
public static function minLength($value, $param)
    {
        $length = is_array($value) ? count($value) : mb_strlen($value);

        return $length >= $param;
    }
1304039
public function isDigitsBetween($value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'digits_between');

        $length = strlen((string)$value);

        return !preg_match('/[^0-9]/', $value)
               && $length >= $parameters[0] && $length <= $parameters[1];
    }
444033
protected function validateLengthMin($field, $value, $params)
    {
        $length = $this->stringLength($value);

        return ($length !== false) && $length >= $params[0];
    }
631822
protected function filter_noise_words($value, $params = null)
    {
        $value = preg_replace('/\s\s+/u', chr(32), $value);

        $value = " $value ";

        $words = explode(',', self::$en_noise_words);

        foreach ($words as $word) {
            $word = trim($word);

            $word = " $word "; // Normalize

            if (stripos($value, $word) !== false) {
                $value = str_ireplace($word, chr(32), $value);
            }
        }

        return trim($value);
    }
1045399
def truncatechars(value,arg=50): 
    '''
    
    ''' 
    arg = int(arg) 
    if arg < len(value): 
        half = (arg-3)/2 
        return "%s...%s" % (value[:half],value[-half:]) 
    return value
155803
public function trim($values = " \t\n\r\0\x0B"): Utility
    {
        $parameters = $this->parameters($values);

        $string = trim($this->string, implode('', $parameters));

        return new static($string, $this->encoding);
    }
255192
private function check($value, $params) {

		if(true === is_string($value) || is_numeric($value)) {
			return strlen($value) >= (int) $params[0];
		}

		return false;
	}
203190
public static function parametrize($str, $params)
    {
        $keys = array_keys($params);
        $vals = array_values($params);

        array_walk($keys, function(&$key) {
            $key = '%' . $key . '%';
        });

        return str_replace($keys, $vals, $str);
    }
1238889
protected function stripPadding($value)
	{
		$pad = ord($value[($len = strlen($value)) - 1]);

		return $this->paddingIsValid($pad, $value) ? substr($value, 0, strlen($value) - $pad) : $value;
	}
1257292
public static function lengths($value, $length)
    {
        if (is_array($length)) {
            foreach ($length as $strlen) {
                if (mb_strlen($value) === $strlen) {
                    return true;
                }
            }

            return false;
        }

        return mb_strlen($value) === $length;
    }