atom  = [CFWS] 1*atext [CFWS]
atext = ; Any character except controls, SP, and specials.

This method doesn't just silently skip over WS.

@param string &$str  The atom/dot data.

@throws Horde_Mail_Exception
542758
protected function _rfc822ParseAtomOrDot(&$str)
    {
        while ($this->_ptr < $this->_datalen) {
            $chr = $this->_data[$this->_ptr];
            if (($chr != '.') &&
                /* TODO: Optimize by duplicating rfc822IsAtext code here */
                !$this->_rfc822IsAtext($chr, ',<:')) {
                $this->_rfc822SkipLwsp();
                if (!$this->_params['validate']) {
                    $str = trim($str);
                }
                return;
            }

            $str .= $chr;
            ++$this->_ptr;
        }
    }
492135
static function strfilter($str)
    {
        $str = str_replace(' ', '_', $str);

        $str = strip_tags($str);

        $str = htmlspecialchars($str);

        return $str;
    }
1353356
protected function parse($str)
    {
        $pos = 0;
        $len = strlen($str);

        // Convert infix operators to postfix using the shunting-yard algorithm.
        $output = array();
        $stack = array();
        while ($pos < $len) {
            $next = substr($str, $pos, 1);

            switch ($next) {
                // Ignore whitespace
                case ' ':
                case "\t":
                    $pos++;
                    break;

                // Variable (n)
                case 'n':
                    $output[] = array('var');
                    $pos++;
                    break;

                // Parentheses
                case '(':
                    $stack[] = $next;
                    $pos++;
                    break;

                case ')':
                    $found = false;
                    while (!empty($stack)) {
                        $o2 = $stack[count($stack) - 1];
                        if ($o2 !== '(') {
                            $output[] = array('op', array_pop($stack));
                            continue;
                        }

                        // Discard open paren.
                        array_pop($stack);
                        $found = true;
                        break;
                    }

                    if (!$found) {
                        throw new Exception('Mismatched parentheses');
                    }

                    $pos++;
                    break;

                // Operators
                case '|':
                case '&':
                case '>':
                case '<':
                case '!':
                case '=':
                case '%':
                case '?':
                    $end_operator = strspn($str, self::OP_CHARS, $pos);
                    $operator = substr($str, $pos, $end_operator);
                    if (!array_key_exists($operator, self::$op_precedence)) {
                        throw new Exception(sprintf('Unknown operator "%s"', $operator));
                    }

                    while (!empty($stack)) {
                        $o2 = $stack[count($stack) - 1];

                        // Ternary is right-associative in C
                        if ($operator === '?:' || $operator === '?') {
                            if (self::$op_precedence[$operator] >= self::$op_precedence[$o2]) {
                                break;
                            }
                        } elseif (self::$op_precedence[$operator] > self::$op_precedence[$o2]) {
                            break;
                        }

                        $output[] = array('op', array_pop($stack));
                    }
                    $stack[] = $operator;

                    $pos += $end_operator;
                    break;

                // Ternary "else"
                case ':':
                    $found = false;
                    $s_pos = count($stack) - 1;
                    while ($s_pos >= 0) {
                        $o2 = $stack[$s_pos];
                        if ($o2 !== '?') {
                            $output[] = array('op', array_pop($stack));
                            $s_pos--;
                            continue;
                        }

                        // Replace.
                        $stack[$s_pos] = '?:';
                        $found = true;
                        break;
                    }

                    if (!$found) {
                        throw new Exception('Missing starting "?" ternary operator');
                    }
                    $pos++;
                    break;

                // Default - number or invalid
                default:
                    if ($next >= '0' && $next <= '9') {
                        $span = strspn($str, self::NUM_CHARS, $pos);
                        $output[] = array('value', intval(substr($str, $pos, $span)));
                        $pos += $span;
                        break;
                    }

                    throw new Exception(sprintf('Unknown symbol "%s"', $next));
            }
        }

        while (!empty($stack)) {
            $o2 = array_pop($stack);
            if ($o2 === '(' || $o2 === ')') {
                throw new Exception('Mismatched parentheses');
            }

            $output[] = array('op', $o2);
        }

        $this->tokens = $output;
    }
1261982
public function containsMultibyteChar($str)
    {
        if (! is_string($str)) {
            throw new \InvalidArgumentException(
                'Error: Variable must be of type string but is of type "'.gettype($str).'"'
            );
        }

        return (mb_strlen($str) != strlen($str));
    }
1228658
public function newVar($str) {
		$str = trim($str);
		
		// Try to make it a variable
		if (preg_match('/^[a-zA-Z0-9\'_][a-zA-Z0-9\'_-]*$/', $str))
			return new Atom(EXPR_VAR, $str);
		else {
			return false;
		}
	}
82265
private function _strtoupper($str)
    {
        $str = html_entity_decode($str, ENT_COMPAT);

        if (function_exists('mb_strtoupper')) {
            $str = mb_strtoupper($str, 'UTF-8');
        } else {
            $str = strtoupper($str);
        }

        $str = htmlspecialchars($str, ENT_COMPAT);

        return $str;
    }
807350
public static function Utf7ImapToUtf8($str)
    {
        if ($str instanceof Horde_Imap_Client_Mailbox) {
            return $str->utf8;
        }

        $str = strval($str);

        /* Try mbstring, if available, which should be faster. Don't use the
         * IMAP utf7_* functions because they are known to be buggy. */
        if (is_null(self::$_mbstring)) {
            self::$_mbstring = extension_loaded('mbstring');
        }
        if (self::$_mbstring) {
            return @mb_convert_encoding($str, 'UTF-8', 'UTF7-IMAP');
        }

        $p = '';
        $ptr = &self::$_index64;

        for ($i = 0, $u7len = strlen($str); $u7len > 0; ++$i, --$u7len) {
            $u7 = $str[$i];
            if ($u7 === '&') {
                $u7 = $str[++$i];
                if (--$u7len && ($u7 === '-')) {
                    $p .= '&';
                    continue;
                }

                $ch = 0;
                $k = 10;
                for (; $u7len > 0; ++$i, --$u7len) {
                    $u7 = $str[$i];

                    if ((ord($u7) & 0x80) || ($b = $ptr[ord($u7)]) === -1) {
                        break;
                    }

                    if ($k > 0) {
                        $ch |= $b << $k;
                        $k -= 6;
                    } else {
                        $ch |= $b >> (-$k);
                        if ($ch < 0x80) {
                            /* Printable US-ASCII */
                            if ((0x20 <= $ch) && ($ch < 0x7f)) {
                                throw new Horde_Imap_Client_Exception(
                                    Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."),
                                    Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION
                                );
                            }
                            $p .= chr($ch);
                        } else if ($ch < 0x800) {
                            $p .= chr(0xc0 | ($ch >> 6)) .
                                  chr(0x80 | ($ch & 0x3f));
                        } else {
                            $p .= chr(0xe0 | ($ch >> 12)) .
                                  chr(0x80 | (($ch >> 6) & 0x3f)) .
                                  chr(0x80 | ($ch & 0x3f));
                        }

                        $ch = ($b << (16 + $k)) & 0xffff;
                        $k += 10;
                    }
                }

                /* Non-zero or too many extra bits -OR-
                 * Base64 not properly terminated -OR-
                 * Adjacent Base64 sections. */
                if (($ch || ($k < 6)) ||
                    (!$u7len || $u7 !== '-') ||
                    (($u7len > 2) &&
                     ($str[$i + 1] === '&') &&
                     ($str[$i + 2] !== '-'))) {
                    throw new Horde_Imap_Client_Exception(
                        Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."),
                        Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION
                    );
                }
            } elseif ((ord($u7) < 0x20) || (ord($u7) >= 0x7f)) {
                /* Not printable US-ASCII */
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."),
                    Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION
                );
            } else {
                $p .= $u7;
            }
        }

        return $p;
    }
369868
public function parse($str)
    {
        $this->removeBom($str);

        $data = $this->createM3uData();
        $lines = \explode("\n", $str);

        for ($i = 0, $l = \count($lines); $i < $l; ++$i) {
            $lineStr = \trim($lines[$i]);
            if ('' === $lineStr || $this->isComment($lineStr)) {
                continue;
            }

            if ($this->isExtM3u($lineStr)) {
                $tmp = \trim(\substr($lineStr, 7));
                if ($tmp) {
                    $data->initAttributes($tmp);
                }
                continue;
            }

            $data->append($this->parseLine($i, $lines));
        }

        return $data;
    }
1178566
public static function _escape($str) {
        if (!self::_isConnected()) {
            self::_createConnection();
        }
        return self::$_db->escape($str);
    }
1224398
public function loadHtml($str, $encoding = 'UTF-8')
    {
        $this->saveLocale();

        // FIXME: Determine character encoding, switch to UTF8, update meta tag. Need better http/file stream encoding detection, currently relies on text or meta tag.
        $known_encodings = mb_list_encodings();
        mb_detect_order('auto');
        if (($file_encoding = mb_detect_encoding($str, null, true)) === false) {
            $file_encoding = "auto";
        }
        if (in_array(strtoupper($file_encoding), array('UTF-8','UTF8')) === false) {
            $str = mb_convert_encoding($str, 'UTF-8', $file_encoding);
        }

        $metatags = array(
            '@<meta\s+http-equiv="Content-Type"\s+content="(?:[\w/]+)(?:;\s*?charset=([^\s"]+))?@i',
            '@<meta\s+content="(?:[\w/]+)(?:;\s*?charset=([^\s"]+))"?\s+http-equiv="Content-Type"@i',
            '@<meta [^>]*charset\s*=\s*["\']?\s*([^"\' ]+)@i',
        );
        foreach ($metatags as $metatag) {
            if (preg_match($metatag, $str, $matches)) {
                if (isset($matches[1]) && in_array($matches[1], $known_encodings)) {
                    $document_encoding = $matches[1];
                    break;
                }
            }
        }
        if (isset($document_encoding) && in_array(strtoupper($document_encoding), array('UTF-8','UTF8')) === false) {
            $str = preg_replace('/charset=([^\s"]+)/i', 'charset=UTF-8', $str);
        } elseif (isset($document_encoding) === false && strpos($str, '<head>') !== false) {
            $str = str_replace('<head>', '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">', $str);
        } elseif (isset($document_encoding) === false) {
            $str = '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">' . $str;
        }
        //FIXME: since we're not using this just yet
        $encoding = 'UTF-8';

        // remove BOM mark from UTF-8, it's treated as document text by DOMDocument
        // FIXME: roll this into the encoding detection using UTF-8/16/32 BOM (http://us2.php.net/manual/en/function.mb-detect-encoding.php#91051)?
        if (substr($str, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)) {
            $str = substr($str, 3);
        }

        // Store parsing warnings as messages
        set_error_handler(array("\\Dompdf\\Helpers", "record_warnings"));

        // @todo Take the quirksmode into account
        // http://hsivonen.iki.fi/doctype/
        // https://developer.mozilla.org/en/mozilla's_quirks_mode
        $quirksmode = false;

        if ($this->options->isHtml5ParserEnabled() && class_exists("HTML5_Tokenizer")) {
            $tokenizer = new HTML5_Tokenizer($str);
            $tokenizer->parse();
            $doc = $tokenizer->save();

            // Remove #text children nodes in nodes that shouldn't have
            $tag_names = array("html", "table", "tbody", "thead", "tfoot", "tr");
            foreach ($tag_names as $tag_name) {
                $nodes = $doc->getElementsByTagName($tag_name);

                foreach ($nodes as $node) {
                    self::removeTextNodes($node);
                }
            }

            $quirksmode = ($tokenizer->getTree()->getQuirksMode() > HTML5_TreeBuilder::NO_QUIRKS);
        } else {
            // loadHTML assumes ISO-8859-1 unless otherwise specified on the HTML document header.
            // http://devzone.zend.com/1538/php-dom-xml-extension-encoding-processing/ (see #4)
            // http://stackoverflow.com/a/11310258/264628
            $doc = new DOMDocument("1.0", $encoding);
            $doc->preserveWhiteSpace = true;
            $doc->loadHTML($str);
            $doc->encoding = $encoding;

            // Remove #text children nodes in nodes that shouldn't have
            $tag_names = array("html", "table", "tbody", "thead", "tfoot", "tr");
            foreach ($tag_names as $tag_name) {
                $nodes = $doc->getElementsByTagName($tag_name);

                foreach ($nodes as $node) {
                    self::removeTextNodes($node);
                }
            }

            // If some text is before the doctype, we are in quirksmode
            if (preg_match("/^(.+)<!doctype/i", ltrim($str), $matches)) {
                $quirksmode = true;
            } // If no doctype is provided, we are in quirksmode
            elseif (!preg_match("/^<!doctype/i", ltrim($str), $matches)) {
                $quirksmode = true;
            } else {
                // HTML5 <!DOCTYPE html>
                if (!$doc->doctype->publicId && !$doc->doctype->systemId) {
                    $quirksmode = false;
                }

                // not XHTML
                if (!preg_match("/xhtml/i", $doc->doctype->publicId)) {
                    $quirksmode = true;
                }
            }
        }

        $this->dom = $doc;
        $this->quirksmode = $quirksmode;

        $this->tree = new FrameTree($this->dom);

        restore_error_handler();

        $this->restoreLocale();
    }
516665
protected function setWebAppPrefix($str): void
    {
        $type = gettype($str);
        if (! is_string($str)) {
            throw StrictTypeException::cstrTypeError($str, 'WebApp Prefix');
        }
        $str = strtoupper(trim($str));
        if (strlen($str) < 3) {
            throw InvalidArgumentException::webappPrefixTooShort($str);
        }
        if (strlen($str) > 32) {
            throw InvalidArgumentException::webappPrefixTooLong($str);
        }
        if (preg_match('/[^A-Z0-9]/', $str) !== 0) {
            throw InvalidArgumentException::webappPrefixNotAlphaNumeric($str);
        }
        $this->webappPrefix = $str . '_';
    }
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;
    }
1005255
private function MaxAge($str) {
    if (strpos($str, '.') === false) {
      throw new Exception('File has no extension');
    }
    $str = strrchr($str, '.');
    $str = substr($str, 1);
    return (integer) $str;
  }
1275421
public static function webappPrefixTooShort(string $str)
    {
        $length = strlen($str);
        if ($length === 0) {
            return new self(sprintf(
                'The WebApp Prefix must be at least 3 characters. You supplied an empty Prefix.'
            ));
        } else {
            return new self(sprintf(
                'The WebApp Prefix must be at least 3 characters. You supplied a %s character Prefix: %s',
                $length,
                $str
            ));
        }
    }
103225
public static void writeStringAsText(DataOutput stream, String str) throws IOException {
    byte[] utf8Encoded = str.getBytes(StandardCharsets.UTF_8);
    writeVLong(stream, utf8Encoded.length);
    stream.write(utf8Encoded);
  }
672221
public static function toUnicode($str)
    {
        $mState = 0; // cached expected number of octets after the current octet
        // until the beginning of the next UTF8 character sequence
        $mUcs4 = 0; // cached Unicode character
        $mBytes = 1; // cached expected number of octets in the current sequence

        $out = [];

        $len = strlen($str);

        for ($i = 0; $i < $len; $i++) {
            $in = ord($str{$i});

            if ($mState == 0) {
                // When mState is zero we expect either a US-ASCII character or a
                // multi-octet sequence.
                if (0 == (0x80 & ($in))) {
                    // US-ASCII, pass straight through.
                    $out[] = $in;
                    $mBytes = 1;
                } elseif (0xC0 == (0xE0 & ($in))) {
                    // First octet of 2 octet sequence
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x1F) << 6;
                    $mState = 1;
                    $mBytes = 2;
                } elseif (0xE0 == (0xF0 & ($in))) {
                    // First octet of 3 octet sequence
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x0F) << 12;
                    $mState = 2;
                    $mBytes = 3;
                } elseif (0xF0 == (0xF8 & ($in))) {
                    // First octet of 4 octet sequence
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x07) << 18;
                    $mState = 3;
                    $mBytes = 4;
                } elseif (0xF8 == (0xFC & ($in))) {
                    /* First octet of 5 octet sequence.
                    *
                    * This is illegal because the encoded codepoint must be either
                    * (a) not the shortest form or
                    * (b) outside the Unicode range of 0-0x10FFFF.
                    * Rather than trying to resynchronize, we will carry on until the end
                    * of the sequence and let the later error handling code catch it.
                    */
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x03) << 24;
                    $mState = 4;
                    $mBytes = 5;
                } elseif (0xFC == (0xFE & ($in))) {
                    // First octet of 6 octet sequence, see comments for 5 octet sequence.
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 1) << 30;
                    $mState = 5;
                    $mBytes = 6;
                } else {
                    /* Current octet is neither in the US-ASCII range nor a legal first
                     * octet of a multi-octet sequence.
                     */
                    trigger_error(
                        'utf8_to_unicode: Illegal sequence identifier ' .
                        'in UTF-8 at byte ' . $i,
                        E_USER_WARNING
                    );

                    return false;
                }
            } else {
                // When mState is non-zero, we expect a continuation of the multi-octet
                // sequence
                if (0x80 == (0xC0 & ($in))) {
                    // Legal continuation.
                    $shift = ($mState - 1) * 6;
                    $tmp = $in;
                    $tmp = ($tmp & 0x0000003F) << $shift;
                    $mUcs4 |= $tmp;

                    /**
                     * End of the multi-octet sequence. mUcs4 now contains the final
                     * Unicode codepoint to be output
                     */
                    if (0 == --$mState) {
                        /*
                        * Check for illegal sequences and codepoints.
                        */
                        // From Unicode 3.1, non-shortest form is illegal
                        if (((2 == $mBytes) && ($mUcs4 < 0x0080)) ||
                            ((3 == $mBytes) && ($mUcs4 < 0x0800)) ||
                            ((4 == $mBytes) && ($mUcs4 < 0x10000)) ||
                            (4 < $mBytes) ||
                            // From Unicode 3.2, surrogate characters are illegal
                            (($mUcs4 & 0xFFFFF800) == 0xD800) ||
                            // Codepoints outside the Unicode range are illegal
                            ($mUcs4 > 0x10FFFF)
                        ) {
                            trigger_error(
                                'utf8_to_unicode: Illegal sequence or codepoint ' .
                                'in UTF-8 at byte ' . $i,
                                E_USER_WARNING
                            );

                            return false;
                        }

                        if (0xFEFF != $mUcs4) {
                            // BOM is legal but we don't want to output it
                            $out[] = $mUcs4;
                        }

                        //initialize UTF8 cache
                        $mState = 0;
                        $mUcs4 = 0;
                        $mBytes = 1;
                    }
                } else {
                    /**
                     *((0xC0 & (*in) != 0x80) && (mState != 0))
                     * Incomplete multi-octet sequence.
                     */
                    trigger_error(
                        'utf8_to_unicode: Incomplete multi-octet ' .
                        '   sequence in UTF-8 at byte ' . $i,
                        E_USER_WARNING
                    );

                    return false;
                }
            }
        }
    }
370062
function strToUtf8($str)
	{
		$chars = unpack('C*', $str);
		$cnt = \count($chars);
		for($i=1;$i<=$cnt;$i++)
			$this->_charToUtf8($chars[$i]);
		return implode("",$chars);
	}