Creates raw [annotation => value, [...]] tree

@param  string $str
@return array
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;
    }
481757
public static function replaceRomanArray(array $str) : array
    {
        foreach ($str as $key => $value) {
            $code = Mbstring::mb_ord($value);
            if ($code >= 8544 && $code <= 8555) {
                $str[$key] = self::toRoman($code - 8543);
            } elseif ($code >= 8560 && $code <= 8571) {
                $str[$key] = self::toSmallRoman($code - 8559);
            } else {
                switch ($code) {
                    case 8556:
                        $str[$key] = self::toRoman(50);
                        break;
                    case 8557:
                        $str[$key] = self::toRoman(100);
                        break;
                    case 8558:
                        $str[$key] = self::toRoman(500);
                        break;
                    case 8559:
                        $str[$key] = self::toRoman(1000);
                        break;
                    case 8572:
                        $str[$key] = self::toSmallRoman(50);
                        break;
                    case 8573:
                        $str[$key] = self::toSmallRoman(100);
                        break;
                    case 8574:
                        $str[$key] = self::toSmallRoman(500);
                        break;
                    case 8575:
                        $str[$key] = self::toSmallRoman(1000);
                        break;
                    default:
                        break;
                }
            }
        }
        return $str;
    }
833301
public function loadStr(string $str, array $option = []): Dom
    {
        $this->options = new Options;
        $this->options->setOptions($this->globalOptions)
                      ->setOptions($option);

        $this->rawSize = strlen($str);
        $this->raw     = $str;

        $html = $this->clean($str);

        $this->size    = strlen($str);
        $this->content = new Content($html);

        $this->parse();
        $this->detectCharset();

        return $this;
    }
665603
private function validateJson(string $str) : array
    {
        $ret = json_decode($str,true);
        if ($ret === null){
            throw new CompileErrorException('invalid json value:' . json_last_error_msg(), $this->state);
        }
        if (!is_array($ret)){
            throw new CompileErrorException('@json immediate must be array value.', $this->state);
        }
        return $ret;
    }
1246793
public static function xmlEscape($str)
    {
        // array used to figure what number to decrement from character order value
        // according to number of characters used to map unicode to ascii by utf-8
        $decrement = [];
        $decrement[4] = 240;
        $decrement[3] = 224;
        $decrement[2] = 192;
        $decrement[1] = 0;

        // the number of bits to shift each charNum by
        $shift = [];
        $shift[1][0] = 0;
        $shift[2][0] = 6;
        $shift[2][1] = 0;
        $shift[3][0] = 12;
        $shift[3][1] = 6;
        $shift[3][2] = 0;
        $shift[4][0] = 18;
        $shift[4][1] = 12;
        $shift[4][2] = 6;
        $shift[4][3] = 0;

        $pos = 0;
        // using standard strlen and letting loop determine # of bytes-per-char
        $len = strlen($str);
        $xml = '';

        while ($pos < $len) {
            $asciiPos = ord(substr($str, $pos, 1));
            if (($asciiPos >= 240) && ($asciiPos <= 255)) {
                // 4 chars representing one unicode character
                $thisLetter = substr($str, $pos, 4);
                $pos += 4;
            } else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
                // 3 chars representing one unicode character
                $thisLetter = substr($str, $pos, 3);
                $pos += 3;
            } else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
                // 2 chars representing one unicode character
                $thisLetter = substr($str, $pos, 2);
                $pos += 2;
            } else {
                // 1 char (lower ascii)
                $thisLetter = substr($str, $pos, 1);
                $pos += 1;
            }

            // process the string representing the letter to a unicode entity
            $thisLen = strlen($thisLetter);
            $thisPos = 0;
            $decimalCode = 0;
            while ($thisPos < $thisLen) {
                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
                if ($thisPos == 0) {
                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
                } else {
                    $charNum = intval($thisCharOrd - 128);
                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
                }

                $thisPos++;
            }

            if ($thisLen == 1) {
                $encodedLetter = '&#' . str_pad($decimalCode, 3, '0', STR_PAD_LEFT) . ';';
            } else {
                $encodedLetter = '&#' . str_pad($decimalCode, 5, '0', STR_PAD_LEFT) . ';';
            }

            $c = $decimalCode;


            if ($c > 0 && $c < 32) {
                $xml .= $encodedLetter;
            } else if ($c >= 32 && $c < 127) {
                switch ($thisLetter) {
                    case '<':
                        $xml .= '&lt;';
                        break;
                    case '>':
                        $xml .= '&gt;';
                        break;
                    case '&':
                        $xml .= '&amp;';
                        break;
                    case '"':
                        $xml .= '&quot;';
                        break;
                    default:
                        $xml .= $thisLetter;
                }
            } else {
                $xml .= $encodedLetter;
            }
        }

        // final mutant possibility (the amped amp)
        $xml = str_replace('&amp;amp;', '&amp;', $xml);
        return trim($xml);
    }
1310170
public static function fromName($str){
		
		$strName = \strtoupper(\trim($str));
		
		foreach(static::getConstants() as $name => $value){
			if($strName === \strtoupper($name)){
				return new static($value);
			}
		}
		
		return null;
		
	}
425922
public function parse($str)
    {
        /* Set the tree root back to a fresh DocumentElement. */
        $this->reset();

        $parent = $this->treeRoot;
        $tokenizer = new Tokenizer($str);

        while ($tokenizer->hasNext()) {
            $parent = $this->parseStartState($parent, $tokenizer);
            if ($parent->getCodeDefinition() && false ===
                $parent->getCodeDefinition()->parseContent()) {
                /* We're inside an element that does not allow its contents to be parseable. */
                $this->parseAsTextUntilClose($parent, $tokenizer);
                $parent = $parent->getParent();
            }
        }

        /* We parsed ignoring nest limits. Do an O(n) traversal to remove any elements that
         * are nested beyond their CodeDefinition's nest limit. */
        $this->removeOverNestedElements();

        return $this;
    }
1174551
public function loadTemplateFromString($str)
    {
        $this->source = 'string: '.$str;
        $this->template = $this->tags = [];
        if (!$str) {
            return;
        }
        $this->tag_cnt = [];

        /* First expand self-closing tags {$tag} -> {tag}{/tag} */
        $str = preg_replace('/{\$([-_:\w]+)}/', '{\1}{/\1}', $str);

        $this->parseTemplate($str);

        return $this;
    }
1093590
protected static function prepareValueS($str, array $params = [])
    {
        $result = $str;
        foreach ($params as $key => $value) {
            $result = str_replace('{'.$key.'}', $value, $result);
        }
        return $result;
    }
306012
protected function build($str) {
		if (!$this->blocks) {
			// Regexes for capturing entire blocks
			$this->blocks=[
				'blockquote'=>'/^(?:\h?>\h?.*?(?:\n+|$))+/',
				'pre'=>'/^(?:(?: {4}|\t).+?(?:\n+|$))+/',
				'fence'=>'/^`{3}\h*(\w+)?.*?[^\n]*\n+(.+?)`{3}[^\n]*'.
					'(?:\n+|$)/s',
				'hr'=>'/^\h*[*_-](?:\h?[\*_-]){2,}\h*(?:\n+|$)/',
				'atx'=>'/^\h*(#{1,6})\h?(.+?)\h*(?:#.*)?(?:\n+|$)/',
				'setext'=>'/^\h*(.+?)\h*\n([=-])+\h*(?:\n+|$)/',
				'li'=>'/^(?:(?:[*+-]|\d+\.)\h.+?(?:\n+|$)'.
					'(?:(?: {4}|\t)+.+?(?:\n+|$))*)+/s',
				'raw'=>'/^((?:<!--.+?-->|'.
					'<(address|article|aside|audio|blockquote|canvas|dd|'.
					'div|dl|fieldset|figcaption|figure|footer|form|h\d|'.
					'header|hgroup|hr|noscript|object|ol|output|p|pre|'.
					'section|table|tfoot|ul|video).*?'.
					'(?:\/>|>(?:(?>[^><]+)|(?R))*<\/\2>))'.
					'\h*(?:\n{2,}|\n*$)|<[\?%].+?[\?%]>\h*(?:\n?$|\n*))/s',
				'p'=>'/^(.+?(?:\n{2,}|\n*$))/s'
			];
		}
		// Treat lines with nothing but whitespaces as empty lines
		$str=preg_replace('/\n\h+(?=\n)/',"\n",$str);
		// Initialize block parser
		$len=strlen($str);
		$ptr=0;
		$dst='';
		// Main loop
		while ($ptr<$len) {
			if (preg_match('/^ {0,3}\[([^\[\]]+)\]:\s*<?(.*?)>?\s*'.
				'(?:"([^\n]*)")?(?:\n+|$)/s',substr($str,$ptr),$match)) {
				// Reference-style link; Backtrack
				$ptr+=strlen($match[0]);
				$tmp='';
				// Catch line breaks in title attribute
				$ref=preg_replace('/\h/','\s',preg_quote($match[1],'/'));
				while ($dst!=$tmp) {
					$dst=preg_replace_callback(
						'/(?<!\\\\)\[('.$ref.')(?!\\\\)\]\s*\[\]|'.
						'(!?)(?:\[([^\[\]]+)\]\s*)?'.
						'(?<!\\\\)\[('.$ref.')(?!\\\\)\]/',
						function($expr) use($match) {
							return (empty($expr[2]))?
								// Anchor
								('<a href="'.$this->esc($match[2]).'"'.
								(empty($match[3])?
									'':
									(' title="'.
										$this->esc($match[3]).'"')).'>'.
								// Link
								$this->scan(
									empty($expr[3])?
										(empty($expr[1])?
											$expr[4]:
											$expr[1]):
										$expr[3]
								).'</a>'):
								// Image
								('<img src="'.$match[2].'"'.
								(empty($expr[2])?
									'':
									(' alt="'.
										$this->esc($expr[3]).'"')).
								(empty($match[3])?
									'':
									(' title="'.
										$this->esc($match[3]).'"')).
								' />');
						},
						$tmp=$dst
					);
				}
			}
			else
				foreach ($this->blocks as $func=>$regex)
					if (preg_match($regex,substr($str,$ptr),$match)) {
						$ptr+=strlen($match[0]);
						$dst.=call_user_func_array(
							[$this,'_'.$func],
							count($match)>1?array_slice($match,1):$match
						);
						break;
					}
		}
		return $dst;
	}
1299234
protected function encode($str)
    {
        $args = func_get_args();
        array_shift($args);
        $args = array_map(
            function ($str) {
                return htmlspecialchars($str, ENT_QUOTES);
            },
            $args
        );
        array_unshift($args, $str);

        return call_user_func_array('sprintf', $args);
    }
110946
public function parse($str)
	{
		if ($this->isQuoteHtml() === true)
		{
			$str = htmlspecialchars($str, ENT_QUOTES);
		}

		foreach ($this->getBbCodes() as $key => $val)
		{
			$str = preg_replace($key, $val, $str);
		}

		return $str;
	}
358362
public static function convertStringToXMLValue(string $str) : string
    {
        $str = str_replace("&amp;", "§", $str);
        $str = str_replace("&", "§", $str);
        $str = str_replace("§", "&amp;", $str);
        $str = str_replace("<", "&lt;", $str);
        $str = str_replace(">", "&gt;", $str);
        $str = str_replace("'", "&apos;", $str);
        $str = str_replace("\"", "&quot;", $str);

        return $str;
    }
1286867
public static function xml(string $str) : bool
    {
        $initialSetting = libxml_use_internal_errors();
        libxml_use_internal_errors(true);
        $result = simplexml_load_string($str) !== false;
        libxml_use_internal_errors($initialSetting);

        return $result;
    }
585006
static function proper_parse_str($str)
	{
		// result array
		$arr = array();

		// split on outer delimiter
		$pairs = explode('&', $str);

		// loop through each pair
		foreach ($pairs as $i)
		{
			// split into name and value
			list($name,$value) = explode('=', $i, 2);

			// if name already exists
			if( isset($arr[$name]) )
			{
				// stick multiple values into an array
				if( is_array($arr[$name]) )
					$arr[$name][] = $value;
				else
					$arr[$name] = array($arr[$name], $value);
			}
			// otherwise, simply stick it in a scalar
			else
				$arr[$name] = $value;
		}

		// return result array
		return $arr;
	}
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;
	}
392941
public static function fromString($str)
    {
        $set = new Stringset();
        $data = str_split($str, 1);
        $pos = 0;

        list(,$magic) = unpack('L', self::mergechars($data, $pos, 4));

        if ($magic !== self::MAGIC_NUMBER) {
            throw new Exception("This is not a MO string.");
        }

        list(,$version) = unpack('L', self::mergechars($data, $pos, 4));

        if ($version !== self::REVISION) {
            throw new Exception("This file format revision is not supported.");
        }

        list(,$nstrings) = unpack('L', self::mergechars($data, $pos, 4));
        list(,$ostart) = unpack('L', self::mergechars($data, $pos, 4));
        list(,$tstart) = unpack('L', self::mergechars($data, $pos, 4));

        for ($i = 0; $i < $nstrings; $i += 1) {
            $original = $ostart + ($i * 8);
            $translated = $tstart + ($i * 8);
            $original = unpack('Llength/Loffset', self::mergechars($data, $original, 8));
            $translated = unpack('Llength/Loffset', self::mergechars($data, $translated, 8));

            $id = self::mergechars($data, $original['offset'], $original['length'] + 1, false);
            $value = self::mergechars($data, $translated['offset'], $translated['length'] + 1, false);

            if ($id[strlen($id) - 1] !== self::NUL || $value[strlen($value) - 1] !== self::NUL) {
                throw new Exception("String wasn't NUL-terminated");
            }

            $result = array();

            $id = explode(self::NUL, $id);
            if (count($id) === 3) {
                $result['msgid_plural'] = $id[1];
            }
            $id = explode(self::EOT, $id[0]);
            if (count($id) === 2) {
                $result['msgctxt'] = $id[0];
                $result['msgid'] = $id[1];
            } else {
                $result['msgid'] = $id[0];
            }

            $value = explode(self::NUL, $value);
            array_pop($value);
            $result['msgstr'] = $value;
            $set->add($result);
        }
        return $set;
    }