本文整理汇总了PHP中League\CommonMark\Cursor::advanceWhileMatches方法的典型用法代码示例。如果您正苦于以下问题:PHP Cursor::advanceWhileMatches方法的具体用法?PHP Cursor::advanceWhileMatches怎么用?PHP Cursor::advanceWhileMatches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\CommonMark\Cursor
的用法示例。
在下文中一共展示了Cursor::advanceWhileMatches方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public static function parse(Cursor $cursor)
{
if (null === self::$regexp) {
$regex = RegexHelper::getInstance();
self::$regexp = sprintf('/^\\s*([.#][_a-z0-9-]+|%s%s)(?<!})\\s*/i', $regex->getPartialRegex(RegexHelper::ATTRIBUTENAME), $regex->getPartialRegex(RegexHelper::ATTRIBUTEVALUESPEC));
}
$state = $cursor->saveState();
$cursor->advanceToFirstNonSpace();
if ('{' !== $cursor->getCharacter()) {
$cursor->restoreState($state);
return [];
}
$cursor->advanceBy(1);
if (':' === $cursor->getCharacter()) {
$cursor->advanceBy(1);
}
$attributes = [];
while ($attribute = trim($cursor->match(self::$regexp))) {
if ('#' === $attribute[0]) {
$attributes['id'] = substr($attribute, 1);
continue;
}
if ('.' === $attribute[0]) {
$attributes['class'][] = substr($attribute, 1);
continue;
}
list($name, $value) = explode('=', $attribute, 2);
$first = $value[0];
$last = substr($value, -1);
if (('"' === $first && '"' === $last || "'" === $first && "'" === $last) && strlen($value) > 1) {
$value = substr($value, 1, -1);
}
if ('class' === strtolower(trim($name))) {
foreach (array_filter(explode(' ', trim($value))) as $class) {
$attributes['class'][] = $class;
}
} else {
$attributes[trim($name)] = trim($value);
}
}
if (0 === $cursor->advanceWhileMatches('}')) {
$cursor->restoreState($state);
return [];
}
if (isset($attributes['class'])) {
$attributes['class'] = implode(' ', $attributes['class']);
}
return $attributes;
}
示例2: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if ($this->length === -1) {
if ($cursor->isBlank()) {
$this->lastLineBlank = true;
}
return false;
}
// Skip optional spaces of fence offset
$cursor->advanceWhileMatches(' ', $this->offset);
return true;
}