League\CommonMark\Util\LinkParserHelper::parseLinkLabel PHP Метод

parseLinkLabel() публичный статический Метод

public static parseLinkLabel ( Cursor $cursor ) : integer
$cursor League\CommonMark\Cursor
Результат integer
    public static function parseLinkLabel(Cursor $cursor)
    {
        $escapedChar = RegexHelper::getInstance()->getPartialRegex(RegexHelper::ESCAPED_CHAR);
        $match = $cursor->match('/^\\[(?:[^\\\\\\[\\]]|' . $escapedChar . '|\\\\)*\\]/');
        $length = mb_strlen($match, 'utf-8');
        if ($match === null || $length > 1001) {
            return 0;
        }
        return $length;
    }

Usage Example

Пример #1
0
 /**
  * Attempt to parse a link reference, modifying the refmap.
  *
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(Cursor $cursor)
 {
     if ($cursor->isAtEnd()) {
         return false;
     }
     $initialState = $cursor->saveState();
     $matchChars = LinkParserHelper::parseLinkLabel($cursor);
     if ($matchChars === 0) {
         $cursor->restoreState($initialState);
         return false;
     }
     // We need to trim the opening and closing brackets from the previously-matched text
     $label = substr($cursor->getPreviousText(), 1, -1);
     if (preg_match('/[^\\s]/', $label) === 0) {
         $cursor->restoreState($initialState);
         return false;
     }
     if ($cursor->getCharacter() !== ':') {
         $cursor->restoreState($initialState);
         return false;
     }
     // Advance past the colon
     $cursor->advance();
     // Link URL
     $cursor->advanceToFirstNonSpace();
     $destination = LinkParserHelper::parseLinkDestination($cursor);
     if (empty($destination)) {
         $cursor->restoreState($initialState);
         return false;
     }
     $previousState = $cursor->saveState();
     $cursor->advanceToFirstNonSpace();
     $title = LinkParserHelper::parseLinkTitle($cursor);
     if ($title === null) {
         $title = '';
         $cursor->restoreState($previousState);
     }
     // Make sure we're at line end:
     if ($cursor->match('/^ *(?:\\n|$)/') === null) {
         $cursor->restoreState($initialState);
         return false;
     }
     if (!$this->referenceMap->contains($label)) {
         $reference = new Reference($label, $destination, $title);
         $this->referenceMap->addReference($reference);
     }
     return true;
 }
All Usage Examples Of League\CommonMark\Util\LinkParserHelper::parseLinkLabel