Returns an array of closures that can check and format
to the $string type

@param $string
@return array
@throws \Exception
962727
function compileString($string) {
        /**
         * Examples:
         *  numeric[-10, 30)
         *  integer(0, inf)
         *  float[0,1]
         */
        $numeric = '/^(numeric|float|integer|int)((\(|\[).+,[^\]\)]+(\)|\]))$/';
        /**
         * Examples:
         *  string{pendent, payed, ready, cancelled}
         *  integer{10, 100, 1000}
         *  scalar{0, false}
         *  {0, false} //same as the previous one
         */
        $valueSetScalar = '/^(scalar|string|float|integer|int|str|boolean|bool|numeric)?(\{[^}]*\})$/';

        /**
         * Examples:
         *  string(5..10)
         *  string(5..)
         *  string(..10)
         *  string(5..5) // strict length
         *  string(..) // pointless, but valid
         */
        $lengthString = '/^string(\(\d*\.\.\d*\))$/';

        /**
         * Examples:
         *  (string|integer)[]
         *  (string|integer{0,1})[]
         *  (bool{true}|integer[1,inf))[]
         */
        $quickArray = "/^(\\(.+(\\|.+)+\\)|[^\\|]*)\\[(\\d+|\\d*\\+|\\*|\\d*\\.\\.\\d*)?\\]$/";

        $identityStructure = array(
            "check" => function($data, $null, &$failed) { return true; },
            "format" => function($data) { return $data; }
        );

        // allow "type1|type2|..."
        $types = explode("|", $string);

        if (preg_match($quickArray, $string)) {
            $structure = new ArrayS();
            $structure->setFormat($string);
            $structure->setCountStrict($this->countStrict);
            $arrayStructure = true;

            $objects = array($structure);
            $i = count($types) + 1;
        } else {
            /** @var Structure[] $objects */
            $objects = array();

            // Use a do-while to check always $type[0]
            $i = 0;
        }
        while (count($types) > $i) {
            $type = $types[$i];
            if (preg_match($numeric, $type, $matches)) {
                switch ($type[0]) {
                    case "n": $structure = new NumericS(); break;
                    case "f": $structure = new FloatS(); break;
                    case "i": $structure = new IntegerS(); break;
                }
                /** @var NumericS $structure */
                $structure->setRange($matches[2]);
            } else if (preg_match($valueSetScalar, $type, $matches)) {
                switch ($type[0] . $type[1]) {
                    default: //fall through to _scalar_
                    case "sc": $structure = new ScalarS(); break;
                    case "st": $structure = new StringS(); break;
                    case "nu": $structure = new NumericS(); break;
                    case "fl": $structure = new FloatS(); break;
                    case "in": $structure = new IntegerS(); break;
                    case "bo": $structure = new BooleanS(); break;
                }
                /** @var ScalarS $structure */
                $structure->setValueSet($matches[2]);
            } else if (preg_match($lengthString, $type, $matches)) {
                $structure = new StringS();
                $structure->setLength($matches[1]);
            } else if (preg_match($quickArray, $type, $matches)) {
                $structure = new ArrayS();
                $structure->setFormat($type);
                $structure->setCountStrict($this->countStrict);
                $arrayStructure = true;
            } else {
                switch ($type) {
                    case "scalar": $structure = new ScalarS(); break;
                    case "string":// fall through to _str_
                    case "str": $structure = new StringS(); break;
                    case "numeric": $structure = new NumericS(); break;
                    case "integer":// fall through to _int_
                    case "int": $structure = new IntegerS(); break;
                    case "float": $structure = new FloatS(); break;
                    case "boolean":// fall through to _bool_
                    case "bool": $structure = new BooleanS(); break;
                    case "array":
                        $structure = new ArrayS();
                        $structure->setFormat("array");
                        $structure->setCountStrict($this->countStrict);
                        break;
                    case "*":
                    case "any":
                        // set structure:identity
                        $structure = $identityStructure;
                        break;
                    case "null":
                    case null:
                        // set structure:null
                        $structure = array(
                            "check" => function($data, $null, &$failed) {
                                $valid = is_null($data);
                                if (!$valid) $failed = Structure::typeof($data);
                                return $valid;
                            },
                            "format" => function() { return null; }
                        );
                        break;
                    default:
                        if (class_exists($string)) {
                            // todo: create ObjectS class
                            $structure = array(
                                "check" => function($data, $null, &$failed) use ($string) {
                                    if (is_null($data)) $valid = $null;
                                    else $valid = $data instanceof $string;

                                    if (!$valid) $failed = Structure::typeof($data);
                                    return $valid;
                                },
                                "format" => $identityStructure["format"]
                            );
                        } else {
                            // maybe $format is a simple array (type[] or type[int])
                            $structure = new ArrayS();
                            $structure->setFormat($type);
                            $structure->setCountStrict($this->countStrict);
                            $arrayStructure = true;
                        }
                        break;
                }
                //prevent errors
                if (!isset($structure)) {
                    $structure = $identityStructure;
                }
            }

            // Add the Structure to use it after the loop
            $objects[] = $structure;
            $i++;
        }

        /**
         * Define return functions, depending on the number of $objects
         * (1 or more)
         */
        $ret = array();
        if ($i == 1) {
            if ($objects[0] instanceof Structure) {
                $check = function ($data, $null, &$failed) use ($objects) {
                    $objects[0]->setNull($null);
                    return $objects[0]->check($data, $failed);
                };
                $format = function ($data, $null) use ($objects) {
                    $objects[0]->setNull($null);
                    return $objects[0]->format($data);
                };
            } else {
                $check = $objects[0]["check"];
                $format = function ($data) use ($objects) {
                    return call_user_func($objects[0]["format"], $data);
                };
            }
        } else {
            $check = function($data, $null, &$failed) use ($objects) {
                foreach ($objects as $obj) {
                    if ($obj instanceof Structure) {
                        $obj->setNull($null);
                        if ($obj->check($data, $failed)) return true;
                    } else if (is_array($obj) && isset($obj["check"])) {
                        $check = $obj["check"];
                        if ($check($data, $null, $failed)) return true;
                    }
                }
                return false;
            };
            $format = function($data, $null) use ($objects) {
                foreach ($objects as $obj) {
                    try {
                        if ($obj instanceof Structure) {
                            $obj->setNull($null);
                            return $obj->format($data);
                        } else {
                            return call_user_func($obj["format"], $data);
                        }
                    } catch (\Exception $e) {}
                }
                throw new \Exception("Unable to format \$data");
            };
        }
        $ret["check"] = $check;
        $ret["format"] = $format;

        if (isset($arrayStructure) && $arrayStructure) {
            $ret["meta"] = "array";
        }

        return $ret;
    }
772179
public function parseAttributes($string)
    {
        $result = array();

        if (!empty($string))
        {
            $pattern = '#(?(DEFINE)
                (?<name>[a-zA-Z][a-zA-Z0-9-_:]*)
                (?<value_double>"[^"]+")
                (?<value_none>[^\s>]+)
                (?<value>((?&value_double)|(?&value_none)))
            )
            (?<n>(?&name))[\s]*(=[\s]*(?<v>(?&value)))?#xs';

            if (preg_match_all($pattern, $string, $matches, PREG_SET_ORDER))
            {
                foreach ($matches as $match) {
                    if (!empty($match['n'])) {
                        $result[$match['n']] = isset($match['v']) ? trim($match['v'], '\'"') : '';
                    }
                }
            }
        }

        return $result;
    }
1225779
public function getCurrentFormatting($string)
    {
        $stack = [];
        foreach ($this->getStyleStack($string) as $style) {
            if (preg_match(static::REGEX_FIRST_KEY, $style, $matches)) {
                $key = $matches[0];

                // if this is a valid setting style, add it to the stack
                if (array_key_exists($key, $this->formats)) {
                    $stack[] = ['key' => $key, 'style' => $style];
                } else {
                    // otherwise remove all elements that this turns off from the current stack
                    if ($key === static::STYLE_RESET) {
                        $stack = [];
                    } else {
                        $stack = array_filter($stack, function ($item) use ($key) {
                            return !in_array($key, $this->formats[$item['key']]);
                        });
                    }
                }
            }
        }

        if (count($stack) === 0) {
            return '';
        }

        $items = array_map(function ($item) {
            return $item['style'];
        }, $stack);
        return sprintf(static::ESCAPE . '[%sm', implode(';', $items));
    }
981994
private static function split(string $string): array
    {
        $chars = [];

        for ($i = 0; $i < strlen($string); $i++) {
            $chars[] = $string[$i];
        }

        return $chars;
    }
669359
public static function initializeByString($string) {
        $Object = json_decode($string);
        $result = self::checkStatus($Object->status);
        if ($result === true) {
            $Status = new self();
            $Status->setStatus($Object->status)
                ->setReceipt(Receipt::initializeByObject($Object->receipt));
            return $Status;
        } else {
            $Exception = new $result($string, $Object->status);
            throw $Exception;
        }
    }
591338
public function getDirtyWordsFromString($string)
    {
        $badWords = [];
        $wordsToTest = $this->flattenArray($this->badWords);

        foreach ($wordsToTest as $word) {

            $word = preg_quote($word);

            if (preg_match($this->buildRegex($word), $string, $matchedString)) {

                $badWords[] = $matchedString[0];
            }
        }

        return $badWords;
    }
365243
public function getArrayWhereKeysBeginWith($string)
    {
        if (empty($this->config)) {
            $this->getArray();
        }
        $config = $this->config;

        $thisConfig = array();
        $cleanNameLength = mb_strlen($string);
        $string = mb_strtolower($string);
        foreach ($config as $key => $value) {
            $begin = substr($key, 0, $cleanNameLength);
            if (mb_strtolower($begin) == $string) {
                $thisConfig[$key] = $value;
            }
        }
        return $thisConfig;
    }
8305
public function getTokens($string)
    {
        $tokens      = [];
        $scanResults = $this->engine->getTokenizer()->scan($string);

        foreach ($scanResults as $scanResult) {
            if (
                isset($scanResult['type'])
                && isset($scanResult['name'])
                && \Mustache_Tokenizer::T_ESCAPED === $scanResult['type']
            ) {
                $tokens[$scanResult['name']] = true;
            }
        }

        return array_keys($tokens);
    }
996049
public function slug($string) {
		if ($this->_config['slugger']) {
			$callable = $this->_config['slugger'];
			if (!is_callable($callable)) {
				throw new RuntimeException('Invalid callable passed as slugger.');
			}

			return $callable($string);
		}

		return Inflector::slug($string);
	}
201631
protected function parse_vars($string)
	{
		foreach ($this->vars as $var => $val)
		{
			$string = str_replace("%$var%", $val, $string);
		}

		return $string;
	}
900947
private function parse($string)
    {
        $params = explode(PHP_EOL, trim($string));
        $result = [];

        foreach ($params as $param) {
            $parts = explode(':', $param);
            $result[$parts[0]] = trim($parts[1]);
        }

        return $result;
    }
1354596
private function eventTokenDecode($string)
    {
        list($campaignIdString, $eventIdString, $contactIdString) = explode('0', $string);

        return [
            $this->baseDecode($campaignIdString),
            $this->baseDecode($eventIdString),
            $this->baseDecode($contactIdString),
        ];
    }
1273230
public static function map($string, callable $callback, $encoding = null)
    {
        $result = [];

        foreach (Mbstring::strSplit($string, 1, $encoding) as $key => $char) {
            if ($callback instanceof \Closure) {
                $result[] = $callback($char, $key);
            } else {
                $result[] = $callback($char);
            }
        }

        return implode('', $result);
    }
95801
public function parse($string)
    {
        if (! $this->isSupports($string)) throw new \InvalidArgumentException('invalid string.');

        $define = new OptionDefine();
        preg_match($this->regexp_option, $string, $matches);

        // optional | required
        if ($matches[1] === 'require') $define->required();

        // long-name
        $define->setName($this->pickName($matches[2]));
        
        // short-name
        $define->setShortName($this->pickShortName($matches[2]));

        // defalt value
        $define->setDefault($this->pickValue($define, $matches[2]));
        
        // description
        $define->setDescription($this->pickDescription($matches));

        return $define;
    }
316576
public function stringify($string, $return_array = false)
    {
        // Makes sure that it's not empty and it's not a 0, 1, 2 etc...
        if (empty($string) && !is_numeric($string)) {
            return;
            // If the string is actually a closure, execute the closure and return it.
        } elseif ($string instanceof Closure) {
            // Run $this->stringify because we don't know what it returns and we want to be sure it's a string. or array
            return $this->stringify($this->run($string), $return_array);
            // Check if $string is an array.
        } elseif (is_array($string)) {
            // As long as $return_array is true return the array, $string.
            if ($return_array) {
                return $string;
            }
            // If $return array is false, join all $string parts with a '-'
            return implode('-', $string);
        } elseif (is_object($string)) {
            // If $string is an object check if it has a __toString function, if it does return that.
            if (method_exists($string, '__toString')) {
                return $string->__toString(); // this will return the is_array() version of the object,
                // If $string is an object cast it to an array and re-run this function.
            } else {
                return $this->stringify((array) $string, $return_array);
            }
            // converting it to an array then to a string imploding with '-'. #recursion
        } elseif (is_numeric($string)) {
            return (string) $string;
            // As long as it's a string just return the $string variable.
        } elseif (is_string($string)) {
            return $string;
        }

        // What ever the hell you put in... We don't support it :P ...
        // Sorry, maybe try casting it or implementing a
        // __toString() method.
        throw new UnexpectedTypeException("We don't know what type your variable is!",
            'Anything but that'); // Not exactly helpful...
    }
691171
static public function formatError($string)
    {
        $words = explode('-', $string);
        $f = 'error';

        foreach($words as $word) {
            $f .= ucfirst($word);
        }

        return $f;
    }
119341
protected function execute($string)
    {
        foreach ($this->patternsAndReplacements as $patternAndReplacement) {
            $tmp = preg_replace("/".$patternAndReplacement->pattern."/s", $patternAndReplacement->replacement, $string);
            if ($tmp === null) {
                InvalidExpression::invalidRegex($patternAndReplacement->pattern, $patternAndReplacement->replacement);
            } else {
                $string = $tmp;
            }
        }
        
        return $string;
    }