Automattic\WooCommerce\Vendor\Sabberworm\CSS\Parsing

ParserState::parseCharacterpublicWC 1.0

Method of the class: ParserState{}

No Hooks.

Returns

String|null.

Usage

$ParserState = new ParserState();
$ParserState->parseCharacter( $bIsForIdentifier );
$bIsForIdentifier(true|false) (required)
.

ParserState::parseCharacter() code WC 10.8.1

public function parseCharacter($bIsForIdentifier)
{
    if ($this->peek() === '\\') {
        if (
            $bIsForIdentifier && $this->oParserSettings->bLenientParsing
            && ($this->comes('\0') || $this->comes('\9'))
        ) {
            // Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing.
            return null;
        }
        $this->consume('\\');
        if ($this->comes('\n') || $this->comes('\r')) {
            return '';
        }
        if (preg_match('/[0-9a-fA-F]/Su', $this->peek()) === 0) {
            return $this->consume(1);
        }
        $sUnicode = $this->consumeExpression('/^[0-9a-fA-F]{1,6}/u', 6);
        if ($this->strlen($sUnicode) < 6) {
            // Consume whitespace after incomplete unicode escape
            if (preg_match('/\\s/isSu', $this->peek())) {
                if ($this->comes('\r\n')) {
                    $this->consume(2);
                } else {
                    $this->consume(1);
                }
            }
        }
        $iUnicode = intval($sUnicode, 16);
        $sUtf32 = "";
        for ($i = 0; $i < 4; ++$i) {
            $sUtf32 .= chr($iUnicode & 0xff);
            $iUnicode = $iUnicode >> 8;
        }
        return iconv('utf-32le', $this->sCharset, $sUtf32);
    }
    if ($bIsForIdentifier) {
        $peek = ord($this->peek());
        // Ranges: a-z A-Z 0-9 - _
        if (
            ($peek >= 97 && $peek <= 122)
            || ($peek >= 65 && $peek <= 90)
            || ($peek >= 48 && $peek <= 57)
            || ($peek === 45)
            || ($peek === 95)
            || ($peek > 0xa1)
        ) {
            return $this->consume(1);
        }
    } else {
        return $this->consume(1);
    }
    return null;
}