League\CommonMark\Cursor::getFirstNonSpacePosition PHP Method

getFirstNonSpacePosition() public method

Returns the position of the next non-space character
    public function getFirstNonSpacePosition()
    {
        if ($this->firstNonSpaceCache !== null) {
            return $this->firstNonSpaceCache;
        }
        $i = $this->currentPosition;
        $cols = $this->column;
        while (($c = $this->getCharacter($i)) !== null) {
            if ($c === ' ') {
                $i++;
                $cols++;
            } elseif ($c === "\t") {
                $i++;
                $cols += 4 - $cols % 4;
            } else {
                break;
            }
        }
        $nextNonSpace = $c === null ? $this->length : $i;
        $this->indent = $cols - $this->column;
        return $this->firstNonSpaceCache = $nextNonSpace;
    }

Usage Example

 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $match = RegexHelper::matchAt(RegexHelper::getInstance()->getHtmlBlockOpenRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
     if ($match === null) {
         return false;
     }
     $context->addBlock(new HtmlBlock());
     $context->setBlocksParsed(true);
     return true;
 }
All Usage Examples Of League\CommonMark\Cursor::getFirstNonSpacePosition