Trim by pattern.

@param string $value
@param array $params :

- pattern: regexp pattern
- limit

@return string
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']);
    }
331145
private function trimTag(string $value): string
    {
        if ('!' === $value[0]) {
            return \ltrim(\substr($value, 1, \strcspn($value, " \r\n", 1)), ' ');
        }

        return $value;
    }
213774
protected function validateDigits($field, $value, $params)
    {
        return !preg_match('/[^0-9]/', $value) && strlen((string) $value) == $params[0];
    }
1252935
private function parseParameter(string $key, string $value, &$params): string
    {
        if (isset($params[$key])) {
            $par = $params[$key];
            unset($params[$key]);

            $value = $value ? $value . '_' . $par : $par;
        }

        return static::makeParam($key, $value);
    }
395079
protected static function processString(&$value, $options)
    {
        $value = str_replace(chr(0), '', $value);
        if (isset($options['length']) && $options['length']) {
            $value = substr($value, 0, $options['length']);
        }

        if (isset($options['regex']) && $options['regex']) {
            if (!preg_match($options['regex'], $value)) {
                $value = null;
            }
        }
    }
292283
public static function fromString($value)
    {
        $parts = array_filter(array_map('trim', explode(';', $value)));

        if (empty($parts) || !strpos($parts[0], '=')) {
            return [];
        }
        $config = [];

        $pieces = explode('=', array_shift($parts), 2);

        if (count($pieces) !== 2) {
            return [];
        }
        $config['name'] = trim($pieces[0]);
        $config['value'] = urldecode(trim($pieces[1], " \n\r\t\0\x0B"));

        foreach ($parts as $item) {
            $pieces = explode('=', trim($item), 2);
            $pieces[0] = strtolower($pieces[0]);
            if (count($pieces) !== 2) {
                $config[$pieces[0]] = true;
            } else {
                $config[$pieces[0]] = $pieces[1];
            }
        }
        return new static($config);
    }
819719
public function filter($value)
    {
        if (!is_scalar($value) && !is_array($value)) {
            return $value;
        }

        if (StringUtils::hasPcreUnicodeSupport()) {
            $pattern     = ['#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#'];
            $replacement = [$this->separator . '\1', $this->separator . '\1'];
        } else {
            $pattern     = ['#(?<=(?:[A-Z]))([A-Z]+)([A-Z][a-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'];
            $replacement = ['\1' . $this->separator . '\2', $this->separator . '\1'];
        }

        return preg_replace($pattern, $replacement, $value);
    }
102924
public function tidy($value) {
		if (is_array($value)) {
			$value = array_map([&$this, 'tidy'], $value);
		} else {
			$value = trim($value);
			// unify line breaks
			$value = preg_replace("=(\r\n|\r)=", "\n", $value);
			// filter nullbyte
			$value = str_replace("\0", '', $value);
		}
		return $value;
	}
204211
public function _prepValues($value)
    {
        if (is_array($value)) {
            if (isset($value["func"])) {
                return $value["func"];
            }
            foreach ($value as &$param) {
                $this->params[] = $param;
                $param = "?";
            }
            unset($param);
            return $value;
        }
        if (in_array(is_string($value) ? strtolower($value) : $value, [null, "null"]) === false) {
            $this->params[] = $value;
            $value = "?";
        }
        return $value;
    }
801198
public static String trim(final String value, final boolean trimmed) {
        if(!trimmed || value == null) {
            return value;
        }

        return value.trim();

    }
255192
private function check($value, $params) {

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

		return false;
	}
48459
public static function varNull($value, array $params = array()) {
        $params['notempty'] = false;
        
        return self::_validateValue('string', $value, $params, true);
    }
1225716
private function filterMessage($param, $value)
    {
        $messages = session($this->session_key, []);

        $filtered_messages = [];
        foreach ($messages as $message) {
            if ($message[$param] == $value) {
                $filtered_messages[] = $message;
            }
        }

        return $filtered_messages;
    }
983626
public static function trim($value, $charlist = NULL, $utf8 = TRUE, $nullable = FALSE)
	{
		if (NULL !== $value) {
			if ($utf8) {
				$value = Kohana_UTF8::trim($value, $charlist);
				if (!Kohana_UTF8::strlen($value) && $nullable) $value = NULL;
			} else {
				$value = trim($value, $charlist);
				if (!strlen($value) && $nullable) $value = NULL;
			}
		}

		return $value;
	}
50792
public static String format(final String value, String... params) {
        validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
        Pattern p = Pattern.compile("\\{(\\w+)}");
        Matcher m = p.matcher(value);
        String result = value;
        while (m.find()) {
            int paramNumber = Integer.parseInt(m.group(1));
            if (params == null || paramNumber >= params.length) {
                throw new IllegalArgumentException("params does not have value for " + m.group());
            }
            result = result.replace(m.group(), params[paramNumber]);
        }
        return result;
    }
678479
public function filter($value, $options = [])
    {
        if ($this->getPattern() == null) {
            $ex = new \Exception(get_class($this) . ' does not have a valid MatchPattern set.');
            throw $ex;
        }

        return preg_replace($this->getPattern(), $this->getReplacement(), $value);
    }
1236859
public static function truncateWords($value, array $params)
    {
        if (empty($params['length']) || !is_numeric($params['length'])) {
            $params['length'] = 100;
        }

        return StringHelper::truncateWords($value, (int)$params['length']);
    }