Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Scanner.php

function Scanner::consumeUnicodeEscapeSequence

Consumes an unicode escape sequence

Return value

array|null

1 call to Scanner::consumeUnicodeEscapeSequence()
Scanner::scanKeywordOrIdentifier in vendor/mck89/peast/lib/Peast/Syntax/Scanner.php
Keywords and identifiers scanning method

File

vendor/mck89/peast/lib/Peast/Syntax/Scanner.php, line 1701

Class

Scanner
Base class for scanners.

Namespace

Peast\Syntax

Code

protected function consumeUnicodeEscapeSequence() {
    if ($this->charAt() !== "\\" || $this->charAt($this->index + 1) !== "u") {
        return null;
    }
    $startIndex = $this->index;
    $startColumn = $this->column;
    $this->index += 2;
    $this->column += 2;
    $brackets = false;
    if ($this->charAt() === "{") {
        
        //\u{FFF}
        $brackets = true;
        $this->index++;
        $this->column++;
        $code = $this->consumeNumbers("x");
        if ($code && $this->charAt() !== "}") {
            $code = null;
        }
        else {
            $this->index++;
            $this->column++;
        }
    }
    else {
        
        //\uFFFF
        $code = $this->consumeNumbers("x", 4);
        if ($code && strlen($code) !== 4) {
            $code = null;
        }
    }
    
    //Unconsume everything if the format is invalid
    if ($code === null) {
        $this->index = $startIndex;
        $this->column = $startColumn;
        return null;
    }
    
    //Return an array where the first element is the matched sequence
    
    //and the second one is the decoded character
    return array(
        $brackets ? "\\u{" . $code . "}" : "\\u" . $code,
        Utils::unicodeToUtf8(hexdec($code)),
    );
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal