charCodeAt() public static method

Returns UTF-8 char code at given $positing of the $string
public static charCodeAt ( $string, $position ) : mixed
$string
$position
return mixed
Example #1
0
 /**
  * Reads a comment token from the source file.
  *
  * #[\u0009\u0020-\uFFFF]*
  *
  * @param $start
  * @param $line
  * @param $col
  * @param Token $prev
  * @return Token
  */
 private function readComment($start, $line, $col, Token $prev)
 {
     $body = $this->source->body;
     $position = $start;
     do {
         $code = Utils::charCodeAt($body, ++$position);
     } while ($code !== null && ($code > 0x1f || $code === 0x9));
     return new Token(Token::COMMENT, $start, $position, $line, $col, $prev, mb_substr($body, $start + 1, $position - $start + 1, 'UTF-8'));
 }
Example #2
0
 /**
  * Reads from body starting at startPosition until it finds a non-whitespace
  * or commented character, then returns the position of that character for
  * lexing.
  *
  * @param $body
  * @param $startPosition
  * @return int
  */
 private function positionAfterWhitespace($body, $startPosition)
 {
     $bodyLength = mb_strlen($body, 'UTF-8');
     $position = $startPosition;
     while ($position < $bodyLength) {
         $code = Utils::charCodeAt($body, $position);
         // Skip whitespace
         if ($code === 32 || $code === 44 || $code === 160 || $code === 0x2028 || $code === 0x2029 || $code > 8 && $code < 14) {
             ++$position;
             // Skip comments
         } else {
             if ($code === 35) {
                 // #
                 ++$position;
                 while ($position < $bodyLength && ($code = Utils::charCodeAt($body, $position)) && $code !== 10 && $code !== 13 && $code !== 0x2028 && $code !== 0x2029) {
                     ++$position;
                 }
             } else {
                 break;
             }
         }
     }
     return $position;
 }