Parses a json string into an array
@param string $str
@return array
17556
static public function toJson($str)
    {
        $data = \json_decode($str, true);

        switch (json_last_error()) {
            case JSON_ERROR_NONE:
            	return $data;
	        case JSON_ERROR_DEPTH:
	            return array('error' => 'Maximum stack depth exceeded');
	        case JSON_ERROR_STATE_MISMATCH:
	            return array('error' => 'Underflow or the modes mismatch');
	        case JSON_ERROR_CTRL_CHAR:
	            return array('error' => 'Unexpected control character found');
	        case JSON_ERROR_SYNTAX:
	            return array('error' => 'Syntax error, malformed JSON');
	        case JSON_ERROR_UTF8:
	            return array('error' => 'Malformed UTF-8 characters, possibly incorrectly encoded');
	        default:
	            return array('error' => 'Unknown error on JSON file');
        }
    }
1209233
public function parseStringMetadata($str)
    {
        $info = array();
        if (0!==preg_match('~^\[([^\]]+)\]~i', $str, $matches)) {
            $str = str_replace($matches[0], '', $str);
            $types = $matches[1];
            $types_items = explode(';', $types);
            foreach ($types_items as $item) {
                $parts = explode(':', $item);
                if (count($parts)>1) {
                    $info[$parts[0]] = $parts[1];
                } else {
                    $info[] = $parts[0];
                }
            }
        }
        return array($str, $info);
    }
892133
protected function _getDomains($str)
    {
        $domains = array();
        $str = trim($str);
        if (strlen($str)) {
            $str = array_map('trim', preg_split("%[^a-z\-\d\.]+%", strtolower($str)));
            foreach ($str as $domain) {
                if (strlen($domain)) {
                    $domains[] = $domain;
                }
            }
        }
        return $domains;
    }
111639
public static JSONFunction parse( String str ) {
      if( !JSONUtils.isFunction( str ) ) {
         throw new JSONException( "String is not a function. " + str );
      } else {
         String params = JSONUtils.getFunctionParams( str );
         String text = JSONUtils.getFunctionBody( str );
         return new JSONFunction( (params != null) ? StringUtils.split( params, "," ) : null, text != null ? text : "" );
      }
   }
110517
public function parse(string $str): Includes
    {
        // Ignore whitespace
        $str = preg_replace('/\s/', '', $str);

        if (empty($str)) {
            return new Includes();
        }

        // Parse a string in the following format:
        // pets{id,name,owner{id,name},photos:limit(3)}:limit(5):offset(10)

        // Define the current parse state
        $state = [
            // Original string
            'string' => $str,
            // Position in string
            'pos' => 0,
            // Length of the original string being processed
            'len' => 0,
            // Current character being processed
            'char' => null,
            // The accumulated current key for the field
            'buffer' => '',
            // The current parent keys
            'parent' => [],
            // Previous parent
            'prevParent' => null,
            // Our list of keys
            'keys' => [],
            // Our list of params
            'params' => [],
        ];

        // Process each character, moving through the state and build
        while ($state['pos'] < ($len = \strlen($str))) {
            $state['char'] = $str[$state['pos']];
            $state['len'] = $len;

            switch ($state['char']) {
                case '{':
                    // Begin children
                    if (!empty($state['buffer'])) {
                        $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
                        $state['parent'][] = $state['buffer'];
                        $state['buffer'] = '';
                    }
                    break;
                case ',':
                    // Delimiter
                    if (!empty($state['buffer'])) {
                        $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
                        $state['buffer'] = '';
                    }
                    break;
                case '}':
                    // End children
                    if (!empty($state['buffer'])) {
                        $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
                        $state['buffer'] = '';
                    }
                    if (!empty($state['parent'])) {
                        $state['prevParent'] = $state['parent'];
                        array_pop($state['parent']);
                    }
                    break;
                case ':':
                    // Looks like it's a parameter. Eg. :limit(10)
                    // Well, if we have a buffer, then that's our parent, if we don't
                    // we will use the parent we saved when we popped the last parent state.
                    $parentKey = !empty($state['buffer']) ?
                        $this->prefixParentKeys($state['buffer'], $state['parent']) : $this->flattenKeys($state['prevParent']);

                    if (preg_match('/^:(\w+)\(([^)]+)\)/', substr($str, $state['pos']), $match)) {
                        // We have a match
                        list($param, $key, $val) = $match;
                        $len = \strlen($param);

                        // Initialise the parent key in our params associative array
                        if (!isset($state['params'][$parentKey])) {
                            $state['params'][$parentKey] = [];
                        }

                        // Store the param key and value
                        $state['params'][$parentKey][$key] = $val;

                        // Chop our parameter out of the original string
                        $str =
                            substr($str, 0, $state['pos']).
                            substr($str, $state['pos'] + $len);

                        // We need to move the position head back one after the chop
                        // since it will be advanced at the end of the loop
                        $state['pos']--;
                    }
                    break;
                default:
                    // Any other character should just be appended
                    $state['buffer'] .= $state['char'];
                    break;
            }
            $state['pos']++;
        }

        // Finally handle any non-empty buffer
        if (!empty($state['buffer'])) {
            $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
            $state['buffer'] = '';
        }

        return (new Includes())
            ->set($state['keys'])
            ->setParams($state['params']);
    }
1007430
public static function parse($str)
    {
        $bLength = 0;
        if ('b' === $str[0]) {
            $bLength = 1;
        }

        if ('\'' === $str[$bLength]) {
            return str_replace(
                ['\\\\', '\\\''],
                ['\\', '\''],
                substr($str, $bLength + 1, -1)
            );
        } else {
            return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
        }
    }
548866
protected function parseAnnotations($str)
    {
        $annotations = [];
        preg_match_all($this->dataPattern, $str, $found);
        foreach ($found[2] as $key => $value) {
            $annotations[ $this->sanitizeKey($found[1][$key]) ][] = $this->parseValue($value, $found[1][$key]);
        }

        return $annotations;
    }
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;
	}
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`
                }
            }
        }
    }
1166296
public static function fromString(string $str): self
    {
        $rdns = array();
        foreach (DNParser::parseString($str) as $nameComponent) {
            $attribs = array();
            foreach ($nameComponent as list($name, $val)) {
                $type = AttributeType::fromName($name);
                // hexstrings are parsed to ASN.1 elements
                if ($val instanceof Element) {
                    $el = $val;
                } else {
                    $el = AttributeType::asn1StringForType($type->oid(), $val);
                }
                $value = AttributeValue::fromASN1ByOID($type->oid(),
                    $el->asUnspecified());
                $attribs[] = new AttributeTypeAndValue($type, $value);
            }
            $rdns[] = new RDN(...$attribs);
        }
        return new self(...$rdns);
    }
19699
public static LazyElement parse(String str) throws LazyException{
		int index=0;
		while(index<str.length()){
			char ch=str.charAt(index);
			if(ch=='['){
				return new LazyArray(str);
			}
			if(ch=='{'){
				return new LazyObject(str);
			}
			index++;
		}
		throw new LazyException("The given string is not a JSON object or array");
	}
1346441
private static function parseHTTPResponse($str)
    {
        $retval = array(
            'headers' => array(),
            'body' => '',
        );
        $lastfield = false;
        $fields = explode("\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $str));
        foreach ($fields as $field) {
            if (strlen(trim($field)) == 0) {
                $lastfield = ':body';
            } elseif ($lastfield == ':body') {
                $retval['body'] .= $field . "\n";
            } else {
                if (($field[0] == ' ' or $field[0] == "\t") and $lastfield !== false) {
                    $retval['headers'][$lastfield] .= ' ' . $field;
                } elseif (preg_match('/([^:]+): (.+)/m', $field, $match)) {
                    $match[1] = strtolower($match[1]);
                    if (isset($retval['headers'][$match[1]])) {
                        if (is_array($retval['headers'][$match[1]])) {
                            $retval['headers'][$match[1]][] = $match[2];
                        } else {
                            $retval['headers'][$match[1]] = array($retval['headers'][$match[1]], $match[2]);
                        }
                    } else {
                        $retval['headers'][$match[1]] = trim($match[2]);
                    }
                }
            }
        }

        return $retval;
    }
485553
private static function _parseHttpSocketHeader($str) {
    $slice = explode("\r\n", $str);
    $headers = array();

    foreach ($slice as $v) {
      if (false !== strpos($v, "HTTP")) {
        list(, $headers["http_code"]) = explode(" ", $v);
        $headers["status"] = $v;
      } else {
        $item = explode(":", $v);
        $headers[$item[0]] = isset($item[1]) ? $item[1] : '';
      }
    }

    return $headers;
  }
419268
public function parse( $str ) {
        
        $this->reset();
        $parent = $this->treeRoot;
        
        $tokenManager = new TokenManager( $str );
                
        $nodeid = 1;
        $inTag = false;
        while( $tokenManager->hasCurrent() ) {
            // tokens are either "[", "]" or a string that contains neither a opening bracket nor a closing bracket
            
            if( $inTag ) {
                // this token should be a tag name
                
                // explode by = in case there's an attribute
                $pieces = explode('=', $tokenManager->getCurrent(), 2);
                
                // check if it's a closing tag
                if( substr($pieces[0], 0, 1) == "/" ) {
                    $tagName = substr($pieces[0], 1);
                    $closing = true;
                } else {
                    $tagName = $pieces[0];
                    $closing = false;
                }
                                                
                if( ($this->codeExists( $tagName, isset($pieces[1])) || $closing && $this->codeExists($tagName, true)) && $tokenManager->hasNext() && $tokenManager->next() == "]" )
                {
                    if( $closing )
                    {
                        $closestParent = $parent->closestParentOfType( $tagName );
                                                
                        if( $closestParent != null && $closestParent->hasParent() )
                        {
                            // closing an element... move to this element's parent
                            $parent->getCodeDefinition()->decrementCounter();
                            $parent = $closestParent->getParent();
                            $tokenManager->advance();
                            $tokenManager->advance();
                            $inTag = false;
                            continue;
                        }
                        
                    } else {
                        // new element
                        $el = new ElementNode();
                        $code = $this->getCode($tagName, isset($pieces[1]));
                        $code->incrementCounter();
                        $el->setNestDepth($code->getCounter());
                        $el->setCodeDefinition($code);
                        $el->setTagName( $tagName );
                        $el->setNodeId( $nodeid++ );
                        if( isset($pieces[1]) )
                            $el->setAttribute( $pieces[1] );
                        
                        $parent->addChild( $el );
                        $parent = $el;
                        $tokenManager->advance();
                        $tokenManager->advance();
                        $inTag = false;
                        continue;
                    }
                }
                
                // the opening bracket that sent us in here was really just plain text
                $node = new TextNode( "[" );
                $node->setNodeId($nodeid++);
                $parent->addChild( $node );
                $inTag = false; 
                // treat this token as regular text, and let the next if...else structure handle it as regular text
                
            }
            
            if( $tokenManager->getCurrent() == "[") {
                $inTag = true;
            }
            else {
                $node = new TextNode( $tokenManager->getCurrent() );
                $node->setNodeId($nodeid++);
                $parent->addChild( $node );
            }
            
            $tokenManager->advance();
            
        }
        
    }
846191
private function extractHeaders($str)
    {
        $this->debug->log(__METHOD__);
        $this->debug->groupUncollapse();
        $headerStart = 0;
        #$this->debug->log(('top', \substr($return, 0, $this->curlInfo['header_size']));
        $headerLenStack = array();
        $i = 0;
        while (true) {
            $headerEnd     = \strpos($str, "\r\n\r\n", $headerStart);
            $headerLength  = $headerEnd - $headerStart;
            $headers       = \substr($str, $headerStart, $headerLength);
            $headerStart   = $headerEnd+4;
            $headerLenStack[] = \strlen($headers)+4;
            #$this->debug->log('headers', \str_replace(array("\r","\n"), array('|','|'), $headers));
            if (\count($headerLenStack) > $this->curlInfo['redirect_count']) {
                #$this->debug->log('header_len_stack','['.\implode(',',$header_len_stack).']');
                $sum = 0;
                for ($j=$i; $j>=0; $j--) {
                    $sum += $headerLenStack[$j];
                    if ($sum == $this->curlInfo['header_size']) {
                        #$this->debug->info('found headers');
                        break 2;
                    }
                }
            }
            if ($headerEnd === false || $i > 20) {
                $this->debug->warn('error parsing headers');
                break;
            }
            $i++;
        }
        // $this->debug->log('headers', $headers);
        return $headers;
    }
170971
public static function get(string $str):array
    {
        $str = trim($str);
        $strArr = Str::toArray($str);
        $results = [];
        foreach ($strArr as $s) {
            $results[] = self::getSingle($s);
        }
        return $results;
    }
631804
public static function parse($string)
  {
    $attr = [];
    $list = [];

    preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

    if ( is_array($attr) ){
      $numPairs = count($attr[1]);
      for ($i = 0; $i < $numPairs; $i++){
        $list[$attr[1][$i]] = $attr[2][$i];
      }
    }
    
    return $list;
  }