A parser for title delimited data.

@param string $str       The string data used to parse
@param string $item      The defined title item to find
@param string $delimiter The default ending delimiter

@return string

@api
763815
public function getTitledItem(string $str, string $item = null, string $delimiter = ';'): string
    {
        return (null === $item)
            ? trim(substr(trim(substr($str, 0)), 0, $this->getStringPositionX(trim(substr($str, 0)), $delimiter, 1)))
            : trim(substr(trim(substr($str, $this->getStringPositionX($str, $item, 1) + strlen($item))), 0, $this->getStringPositionX(trim(substr($str, $this->getStringPositionX($str, $item, 1) + strlen($item))), $delimiter, 1)));
    }
730511
static function titleCase($string, $delimiter = '') {
		return implode($delimiter, array_map('ucfirst', self::getWords($string, true)));
	}
983461
public final function parse($param_str) {
        $params = explode(",", $param_str);
        foreach ($params as $param_item) {
            $param_kv = explode("=", $param_item);
            $param_key = trim($param_kv[0]);
            $param_value = trim($param_kv[1]);
            if ('"' === substr($param_key, 0, 1) && '"' === substr($param_key, -1, 1)) {
                $param_key = substr($param_key, 1, strlen($param_key) - 2);
            }
            if ('"' === substr($param_value, 0, 1) && '"' === substr($param_value, -1, 1)) {
                // This param_value is a string type, which could be set directly
                if (property_exists($this, $param_key)) {
                    $this->$param_key = substr($param_value, 1, strlen($param_value) - 2);
                } else {
                    // @TODO support special variables like from `@use`
                }
            }
        }
    }
327406
public static function csvFileToArrayGenerator(string $filename = '', string $delimiter = ',')
    {
        $complete = false;
        try {
            $header = null;
            if (($handle = fopen($filename, 'r')) !== false) {
                while (($row = fgetcsv($handle, 4096, $delimiter)) !== false) {
                    if (!$header) {
                        $header = $row;
                    } else {
                        yield array_combine($header, $row);
                    }
                }
            }
            $complete = true;
        } finally {
            if (!$complete) {
                // cleanup when loop breaks
            } else {
                // cleanup when loop completes
            }
        }
        // Do something only after loop completes
    }
771938
public static function getVendorPrefixRegExp($delimiter = null)
    {
        $vendorPrefixValues = self::getVendorPrefixValues();
        foreach ($vendorPrefixValues as $vendorPrefixKey => $vendorPrefixValue) {
            $vendorPrefixValues[$vendorPrefixKey] = preg_quote($vendorPrefixValue, $delimiter);
        }
        return implode('|', $vendorPrefixValues);
    }
1034902
public function explode(string $delimiter, int $limit = PHP_INT_MAX): TextVector
    {
        $pieces = explode($delimiter, $this->text, $limit);

        return TextVector::make($pieces);
    }
706883
public static function machine($str, $separator = '_')
    {
        $out = strtolower($str);
        $out = preg_replace('/[^a-z0-9' . $separator . ']/', $separator, $out);
        $out = preg_replace('/' . $separator . '{2,}/', $separator, $out);
        $out = preg_replace('/^' . $separator . '/', '', $out);
        $out = preg_replace('/' . $separator . '$/', '', $out);
        return $out;
    }
1140485
public static function getStrong($str)
    {
        /*
         * Split the content by html tags.
         */
        $tree = preg_split(
            '/(<[^!]?[^>]+>(<![^>]+>)?)/',
            $str,
            -1,
            PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
        );

        /*
         * Initiate variables.
         */
        $r = array();
        $line = '';
        $isInline = true;
        $oneLine = array();
        $lastWasTag = false;

        /*
         * Loop throu the tree.
         */
        foreach ($tree as $k => $elm) {
            /*
             * Check what kind of element this is.
             */
            $info;
            switch (self::_getTreeElm($elm[0], $info)) {
            case 'start':
                /*
                 * It's a starting tag
                 */
                $add = new Tag(
                    $info[1], /* The Tags Name */
                    array(self::parseAttrs($info[2])), /* The attributes */
                    array(
                        'generate',
                        ($info[3] == '/>' ? 'selfQlose' : 'doNotSelfQlose'),
                        'start',
                        (in_array($info[1], TagInfo::$inlineTags) ? 'inline' : null)
                    )
                );
                break;
            case 'end':
                /*
                 * It is a closing tag
                 */
                $add = Store::get();
                break;
            case 'comment':
            case 'content':
            default:
                /*
                 * It's something else
                 */
                $add = $elm[0];
                break;
            }

            /*
             * Add the current content to the output.
             */
            self::_toLine($add, $r, $line, $isInline, $oneLine, $lastWasTag);
        }

        /*
         * Check if there is still content in the current line
         * and add it to the return array.
         */
        if (strlen($line)) {
            $r[] = $line;
        }

        /*
         * implode the return array using line breaks and return the string.
         */

        return implode(Generator::getLineBreak(), $r).Generator::getLineBreak();
    }
581042
public function consumeString($delimiter, $type)
    {
        $close = Utils::balanceDelimiter($delimiter);

        $balanced = $close !== $delimiter;
        $patterns = array('/(?<!\\\\)((?:\\\\\\\\)*)(' . preg_quote($close, '/') . ')/');

        if ($balanced) {
            $patterns[] = '/(?<!\\\\)((?:\\\\\\\\)*)(' . preg_quote($delimiter, '/') . ')/';
        }

        $stack = 1; // we're already inside the string
        $start = $this->pos();
        $closeDelimiterMatch = null;
        while ($stack) {
            $next = $this->getNext($patterns);
            if ($next[0] === -1) {
                $this->terminate();
                $finish = $this->pos();
                break;
            } elseif ($balanced && $next[1][2] === $delimiter) {
                $stack++;
                $finish = $next[0] + strlen($next[1][0]);
            } elseif ($next[1][2] === $close) {
                $stack--;
                if (!$stack) {
                    $closeDelimiterMatch = $next[1][2];
                }
                $finish = $next[0] + strlen($next[1][1]);
            } else {
                assert(0);
            }
            $this->pos($next[0] + strlen($next[1][0]));
        }
        $substr = substr($this->string(), $start, $finish - $start);
        // special case for qw, the string is not a 'STRING', it is actually
        // a whitespace separated list of strings. So we need to split it and
        // record them separately
        if ($type === 'SPLIT_STRING') {
            foreach (preg_split('/(\s+)/', $substr, -1, PREG_SPLIT_DELIM_CAPTURE) as $token) {
                if (preg_match('/^\s/', $token)) {
                    $this->record($token, null);
                } else {
                    $this->record($token, 'STRING');
                }
            }
        } else {
            $this->record($substr, $type);
        }
        if ($closeDelimiterMatch !== null) {
            $this->record($closeDelimiterMatch, 'DELIMITER');
        }
    }
1338972
public static function slug(string $str, string $delimiter = '-') : string
    {
        $str = static::toAscii($str);

        // Remove all characters that are neither alphanumeric, nor the separator nor a whitespace.
        $str = preg_replace('![^'.preg_quote($delimiter).'\pL\pN\s]+!u', '', mb_strtolower($str));

        // Standardize the separator.
        $flip = $delimiter == '-' ? '_' : '-';
        $str = preg_replace('!['.preg_quote($flip).']+!u', $delimiter, $str);

        // Replace all separator characters and whitespace by a single separator.
        $str = preg_replace('!['.preg_quote($delimiter).'\s]+!u', $delimiter, $str);

        return trim($str, $delimiter);
    }
976857
public static function fromString(string $fieldListString, string $delimiter = ',') : PhraseFields
    {
        return self::initializeFromString($fieldListString, $delimiter);
    }
1309168
public function parsePasswordOTP($str, $delim = '[:]')
    {
        if (!preg_match("/^((.*)" . $delim . ")?(([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{0,16})([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{32}))$/", $str, $matches)) {
            /* Dvorak? */
            if (!preg_match("/^((.*)" . $delim . ")?(([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{0,16})([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{32}))$/", $str, $matches)) {
                return false;
            } else {
                $ret['otp'] = strtr($matches[3], "jxe.uidchtnbpygk", "cbdefghijklnrtuv");
            }
        } else {
            $ret['otp'] = $matches[3];
        }

        $ret['password'] = $matches[2];
        $ret['prefix'] = $matches[4];
        $ret['ciphertext'] = $matches[5];

        return $ret;
    }
181182
public function parseAttr($str, $name = null)
    {
        $regex = '/\s+(?>(?P<name>[\w-]+)\s*)=(?>\s*)([\"\'])(?P<value>(?:(?!\\2).)*)\\2/is';
        $array = [];

        if (preg_match_all($regex, $str, $matches, PREG_SET_ORDER)) {
            foreach ($matches as $match) {
                $array[$match['name']] = $match['value'];
            }
            unset($matches);
        }

        if (!empty($name) && isset($array[$name])) {
            return $array[$name];
        } else {
            return $array;
        }
    }
759900
protected function parseInterpolationString($str)
	{
		$parsed = [];

		if ( ! preg_match_all('~\{([a-z\d_\-\|\#]+?)\}~i', $str, $matches))
		{
			return $parsed;
		}

		foreach ($matches[1] as $key => $value)
		{
			$parsed[$matches[0][$key]] = explode('|', $value);
		}

		return $parsed;
	}
816789
public function parseString($str) {
        if (!extension_loaded("SimpleXML"))
            throw new XmlParserException("SimpleXML extension not loaded, can not parse XML");
        
        libxml_use_internal_errors(true);
        $xml = simplexml_load_string($str);
        
        if ($xml === false) {
            $msg = "The following XML errors occurred while parsing:";
            foreach (libxml_get_errors() as $error)
                $msg .= "\n" . $error->message;
            throw new XmlParserException($msg);
        }

        $this->xml = $xml;
        $this->xmlString = $str;
        return $this;
    }
735089
public static function title(string $str, string $encoding = null) : string
    {
        return mb_convert_case($str, MB_CASE_TITLE, $encoding ?: utils\Str::encoding($str));
    }
159779
public static function stringToArray($string = false, $delimiter = ' ', $limit = false) {

        if ($string && Validate::isString($string)) {

            if($limit) {

                return explode($delimiter, $string, $limit);
            }

            return explode($delimiter, $string);
        }

        return false;
    }