return the DOM corresponding to the parameter
@param string $str
@return DOMDocument
175124
public static function getDOM($str)
	{
		//create domdocument
		$dom = new DOMDocument();
		//load by file or string
		is_file($str) ? $dom->load($str) : $dom->loadXML($str);
		// return the DOMDoc
		return $dom;
	}
1279817
public static function getString(&$str)
    {
        $p = strpos($str, "\x00");
        if ($p === false) {
            return '';
        }
        $r   = static::binarySubstr($str, 0, $p);
        $str = static::binarySubstr($str, $p + 1);

        return $r;
    }
152420
public static function parse_attrib_string($str)
    {
        $attrib = array();
        $html   = '<html>'
            . '<head><meta http-equiv="Content-Type" content="text/html; charset=' . RCUBE_CHARSET . '" /></head>'
            . '<body><div ' . rtrim($str, '/ ') . ' /></body>'
            . '</html>';

        $document = new DOMDocument('1.0', RCUBE_CHARSET);
        @$document->loadHTML($html);

        if ($node = $document->getElementsByTagName('div')->item(0)) {
            foreach ($node->attributes as $name => $attr) {
                $attrib[strtolower($name)] = $attr->nodeValue;
            }
        }

        return $attrib;
    }
267510
public static function load($str)
    {
        $dom       = new Dom;
        self::$dom = $dom;

        return $dom->load($str);
    }
1095932
protected function _a($str) {
		$self=$this;
		return preg_replace_callback(
			'/(?<!\\\\)\[(.+?)(?!\\\\)\]\h*\(<?(.*?)>?(?:\h*"(.*?)"\h*)?\)/',
			function($expr) use($self) {
				return '<a href="'.$self->esc($expr[2]).'"'.
					(empty($expr[3])?
						'':
						(' title="'.$self->esc($expr[3]).'"')).
					'>'.$self->scan($expr[1]).'</a>';
			},
			$str
		);
	}
312047
private function createDOMDocumentFromHTML($html = null) {

        if ($html != null) {
            libxml_use_internal_errors(true);
            $dom = new DOMDocument;
            $dom->loadHTML($html);
            libxml_clear_errors();
            libxml_use_internal_errors(false);
            return $dom;
        }
    }
841396
public function compileString($str)
    {
        $loader = new Twig_Loader_String();

        // Instance compiler.
        $twig = $this->getTwigCompiler($loader);

        return $twig->render($str, $this->data);
    }
276133
public static function stripAll($str)
    {
        $str = stripslashes($str);
        $str = strip_tags($str);
        $str = \sb\Strings::unicodeUrldecode($str);
        $str = self::stripBling($str);
        $str = \sb\Strings::stripMicrosoftChars($str);
        return $str;
    }
513746
protected static function ourStrlen($str)
    {
        // Premature optimization: cache the function_exists() result
        static $exists = null;
        if ($exists === null) {
            $exists = \function_exists('\\mb_strlen');
        }

        // If it exists, we need to make sure we're using 8bit mode
        if ($exists) {
            return \mb_strlen($str, '8bit');
        }
        return \strlen($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;
    }
584390
public static function before($str)
    {
        $str = str_replace('\\', '/', $str);
        $i = strrpos($str, '/');
        if ($i === false) {
            return $str;
        }

        return substr($str, 0, $i);
    }
144488
public static function convertNodeStr($str): string
    {
        $str = \trim($str, '-');

        // convert 'first-second' to 'firstSecond'
        if (\strpos($str, '-')) {
            $str = (string)\preg_replace_callback('/-+([a-z])/', function ($c) {
                return \strtoupper($c[1]);
            }, \trim($str, '- '));
        }

        return $str;
    }
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();
            
        }
        
    }
63065
public static function extension(string $str): string
	{
		$pos = strripos($str, '.');

		if ($pos === false) {
			return pathinfo($str, PATHINFO_EXTENSION);
		}

		return substr($str, $pos);
	}
199318
public static function encode(String $str) : String
    {
        return str_replace(array_keys(self::$phpTagChars), array_values(self::$phpTagChars), $str);
    }
1074652
protected function _code($str) {
		$self=$this;
		return preg_replace_callback(
			'/`` (.+?) ``|(?<!\\\\)`(.+?)(?!\\\\)`/',
			function($expr) use($self) {
				return '<code>'.
					$self->esc(empty($expr[1])?$expr[2]:$expr[1]).'</code>';
			},
			$str
		);
	}
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), '"');
        }
    }