本文整理匯總了PHP中League\CommonMark\Cursor::isAtEnd方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cursor::isAtEnd方法的具體用法?PHP Cursor::isAtEnd怎麽用?PHP Cursor::isAtEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類League\CommonMark\Cursor
的用法示例。
在下文中一共展示了Cursor::isAtEnd方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parse
/**
* 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;
}
示例2: parse
/**
* 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:
$atLineEnd = true;
if ($cursor->match('/^ *(?:\\n|$)/') === null) {
if ($title === '') {
$atLineEnd = false;
} else {
// The potential title we found is not at the line end,
// but it could still be a legal link reference if we
// discard the title
$title = '';
// rewind before spaces
$cursor->restoreState($previousState);
// and instead check if the link URL is at the line end
$atLineEnd = $cursor->match('/^ *(?:\\n|$)/') !== null;
}
}
if (!$atLineEnd) {
$cursor->restoreState($initialState);
return false;
}
if (!$this->referenceMap->contains($label)) {
$reference = new Reference($label, $destination, $title);
$this->referenceMap->addReference($reference);
}
return true;
}