@param string $luhn
@param int    $length
@param bool   $unDecorate
@param array  $hyphens

@return bool
192587
public static function check($luhn, $length, $unDecorate = true, $hyphens = [])
    {
        $luhn = $unDecorate ? self::unDecorate($luhn, $hyphens) : $luhn;
        if (strlen($luhn) != $length) {
            return false;
        }
        $expr = sprintf('/\\d{%d}/i', $length);
        if (!preg_match($expr, $luhn)) {
            return false;
        }
        if (0 === (int) $luhn) {
            return false;
        }
        $check = 0;

        for ($i = 0; $i < $length; $i += 2) {
            if ($length % 2 == 0) {
                $check += 3 * (int) substr($luhn, $i, 1);
                $check += (int) substr($luhn, $i + 1, 1);
            } else {
                $check += (int) substr($luhn, $i, 1);
                $check += 3 * (int) substr($luhn, $i + 1, 1);
            }
        }

        return $check % 10 == 0;
    }
923980
public static function isHash($hash, int $length = 32): bool
    {
        return (is_string($hash) || is_int($hash)) && preg_match('#^[0-9a-f]{'.$length.'}$#i', $hash);
    }
636296
public function getDimension($w, $h) {
        $textlength = (3 + ($this->ratio + 1) * 2) * strlen($this->text);
        $startlength = 4;
        $checksumlength = 0;
        if ($this->checksum === true) {
            $checksumlength = (3 + ($this->ratio + 1) * 2);
        }

        $endlength = 2 + ($this->ratio + 1);

        $w += $startlength + $textlength + $checksumlength + $endlength;
        $h += $this->thickness;
        return parent::getDimension($w, $h);
    }
389999
function _unpad($text)
    {
        if (!$this->padding) {
            return $text;
        }

        $length = ord($text[strlen($text) - 1]);

        if (!$length || $length > $this->block_size) {
            return false;
        }

        return substr($text, 0, -$length);
    }
895770
private function setLength($length)
    {
        try {
            $this->length = (float)$length;
            unset($length);
            return 0;
        } catch (\Exception $e) {
            throw $e;
        }
    }
803080
static public function arrangement(array $collection, $length, array &$result, $str = '')
    {
        $count = count($collection);

        if ($length === 0) {
            $result[] = $str;
        } else {
            for ($i = 0; $i < $count; $i++) {
                $item = array_shift($collection);

                if (strlen($str) === 0)
                    $tmp = $item;
                else
                    $tmp = $str . ',' . $item;

                self::arrangement($collection, $length - 1, $result, $tmp);
                array_push($collection, $item);
            }
        }
    }
1086060
private static function isWhitespaceOfLength(TokenInterface $token, int $length): bool
    {
        return static::isWhitespace($token) && strlen(trim($token->getValue(), "\n")) == $length;
    }
418017
public function isCollationSupportedForKeys($collation, $fieldLength)
    {
        $sm = $this->getSchemaManager();
        $existingTables = array_map('strtolower', $sm->listTableNames());
        for ($i = 0; ; ++$i) {
            $tableName = 'tmp_checkCollationFieldLength' . $i;
            if (!in_array(strtolower($tableName), $existingTables)) {
                break;
            }
        }
        $column = new DbalColumn('ColumnName', DbalType::getType(DbalType::STRING), ['length' => (int) $fieldLength]);
        $column->setPlatformOption('collation', (string) $collation);
        $table = new DbalTable($tableName, [$column]);
        $table->setPrimaryKey([$column->getName()]);
        try {
            $sm->createTable($table);
        } catch (Exception $x) {
            // SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is XYZ bytes
            return false;
        }
        try {
            $sm->dropTable($tableName);
        } catch (Exception $x) {
        }

        return true;
    }
1040682
private static function _unpad($text, $blocksize) {
        if (empty($text)) {
            return '';
        }
        if (strlen($text) % $blocksize !== 0) {
            return false;
        }
        $pad = ord($text{strlen($text)-1});
        if ($pad > $blocksize || $pad > strlen($text) || $pad === 0) {
            return false;
        }
        if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
            return false;
        }
        $textNoPadding = substr($text, 0, - $pad); 
        return $textNoPadding;
    }
302277
public String unDecorate( final String str )
        throws PlexusCipherException
    {
        Matcher matcher = ENCRYPTED_STRING_PATTERN.matcher( str );

        if ( matcher.matches() || matcher.find() )
        {
            return matcher.group( 1 );
        }
        else
        {
            throw new PlexusCipherException( "default.plexus.cipher.badEncryptedPassword" );
        }
    }
746969
public static function generate(
        int $length = 8,
        bool $preventAmbiguous = true,
        array $alphabets = null,
        array $rules = null,
        string $allowedSpecialChars = null
    ) {
        $stringUtil = System::getContainer()->get('huh.utils.string');

        $alphabets = \is_array($alphabets) ? $alphabets : static::DEFAULT_ALPHABETS;
        $rules = \is_array($rules) ? $rules : static::DEFAULT_RULES;
        $allowedSpecialChars = null !== $allowedSpecialChars ? $allowedSpecialChars : static::DEFAULT_ALLOWED_SPECIAL_CHARS;

        $generator = new ComputerPasswordGenerator();
        $generator
            ->setLength($length)
            ->setNumbers(\in_array(static::NUMBERS, $alphabets, true) && \in_array(static::NUMBERS, $rules, true))
            ->setUppercase(\in_array(static::CAPITAL_LETTERS, $alphabets, true) && \in_array(static::CAPITAL_LETTERS, $rules, true))
            ->setAvoidSimilar($preventAmbiguous)
            ->setSymbols(\in_array(static::SPECIAL_CHARS, $alphabets, true) && \in_array(static::SPECIAL_CHARS, $rules, true));

        $code = $generator->generatePassword();

        // replace remaining ambiguous characters
        if ($preventAmbiguous) {
            $charReplacements = ['y', 'Y', 'z', 'Z', 'o', 'O', 'i', 'I', 'l'];

            foreach ($charReplacements as $char) {
                $code = str_replace($char, $stringUtil->randomChar(!$preventAmbiguous), $code);
            }
        }

        // apply allowed alphabets
        $forbiddenPattern = '';
        $allowedChars = '';

        if (!\in_array(static::CAPITAL_LETTERS, $alphabets)) {
            $forbiddenPattern .= 'A-Z';
        } else {
            $allowedChars .= ($preventAmbiguous ? StringUtil::CAPITAL_LETTERS_NONAMBIGUOUS : StringUtil::CAPITAL_LETTERS);
        }

        if (!\in_array(static::SMALL_LETTERS, $alphabets)) {
            $forbiddenPattern .= 'a-z';
        } else {
            $allowedChars .= ($preventAmbiguous ? StringUtil::SMALL_LETTERS_NONAMBIGUOUS : StringUtil::SMALL_LETTERS);
        }

        if (!\in_array(static::NUMBERS, $alphabets)) {
            $forbiddenPattern .= '0-9';
        } else {
            $allowedChars .= ($preventAmbiguous ? StringUtil::NUMBERS_NONAMBIGUOUS : StringUtil::NUMBERS);
        }

        if ('' === $allowedChars) {
            return $code;
        }

        if ($forbiddenPattern) {
            $code = preg_replace_callback('@['.$forbiddenPattern.']{1}@', function () use ($allowedChars, $stringUtil) {
                return $stringUtil->random($allowedChars);
            }, $code);
        }

        // special chars
        if (!\in_array(static::SPECIAL_CHARS, $alphabets)) {
            $code = preg_replace_callback('@[^'.$allowedChars.']{1}@', function () use ($allowedChars, $stringUtil) {
                return $stringUtil->random($allowedChars);
            }, $code);
        } else {
            $code = preg_replace_callback('@[^'.$allowedChars.']{1}@', function () use ($allowedSpecialChars, $stringUtil) {
                return $stringUtil->random($allowedSpecialChars);
            }, $code);
        }

        return $code;
    }
465902
public static function SubstringWithLength( $item, $startingLoc, $length )
	{
		if ( $item instanceof Undefined )
		{
			return "";
		}

		$value = (string)$item; // . "";

		if ( $startingLoc instanceof XPath2Item )
		{
			$startingLoc = $startingLoc->getTypedValue();
		}

		if ( $length instanceof XPath2Item )
		{
			$length = $length->getTypedValue();
		}

		if ( $startingLoc == INF ||  $startingLoc == -INF || is_nan( $startingLoc ) || $length == -INF || is_nan( $length ) )
		{
			return "";
		}

		$pos = intval( Round( $startingLoc ) ) - 1;
		$len;
		if ( $length == INF )
		    $len = PHP_INT_MAX;
		else
		    $len = intval( Round( $length ) );

		if ( $pos < 0 )
		{
		    $len = $len + $pos;
		    $pos = 0;
		}

		if ( $pos < strlen( $value ) )
		{
		    if ( $pos + $len > strlen( $value ) )
			   $len = strlen( $value ) - $pos;

		    if ( $len > 0 )
			   return substr( $value, $pos, $len );
		}
		return "";
	}
1323228
public static function isLength($string = false, $minLength = 0, $maxLength = false) {

        if ($string && strlen($string) >= $minLength) {

            if (!$maxLength || strlen($string) <= $maxLength) {

                return true;
            }
        }

        return false;
    }
134865
public static function salts($length)
    {
        $chars = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
        $stringlength = count($chars); //Used Count because its array now
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $chars[rand(0, $stringlength - 1)];
        }

        return $randomString;
    }
955943
public static function generateCustom($prefix, $length=128) {

        if ( $length <= (strlen($prefix)+1) ) {
            throw new InvalidArgumentException("Uid length cannot be smaller than prefix length +1");

        }

        return "$prefix-".self::generate($length-(strlen($prefix)+1));

    }
750710
public static function unDS($str, $unify = false)
    {
        return self::_slash($str, DIRECTORY_SEPARATOR, false, false, $unify);
    }
114383
public function lengthLess($length)
    {
        if (!is_int($length)) {
            throw new InvalidIntException('length', $length);
        } elseif ($length < 0) {
            throw new NumberNotPositiveException('length', $length);
        }

        if (!is_string($this->value)) {
            throw new InvalidStringException($this->name, $this->value);
        } elseif (strlen($this->value) > $length) {
            throw new LengthNotLessException($this->name, $this->value, $length);
        }

        return $this;
    }