本文整理匯總了PHP中Symfony\CS\Tokenizer\Tokens::getNonEmptySibling方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tokens::getNonEmptySibling方法的具體用法?PHP Tokens::getNonEmptySibling怎麽用?PHP Tokens::getNonEmptySibling使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\CS\Tokenizer\Tokens
的用法示例。
在下文中一共展示了Tokens::getNonEmptySibling方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: clearCommentToken
/**
* Clear comment token, but preserve trailing linebreak if there is any.
*
* @param Tokens $tokens
* @param int $index T_COMMENT index
*
* @deprecated Will be removed in the 2.0
*/
private function clearCommentToken(Tokens $tokens, $index)
{
if ("\n" !== substr($tokens[$index]->getContent(), -1, 1)) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// if previous not-cleared token is whitespace;
// append line break to content
$previous = $tokens->getNonEmptySibling($index, -1);
if ($tokens[$previous]->isWhitespace()) {
$tokens[$previous]->setContent($tokens[$previous]->getContent() . "\n");
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// elseif the next not-cleared token is whitespace;
// prepend with line break
$next = $tokens->getNonEmptySibling($index, 1);
if (null !== $next && $tokens[$next]->isWhitespace()) {
$tokens[$next]->setContent("\n" . $tokens[$next]->getContent());
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// else
// override with whitespace token linebreak
$tokens->overrideAt($index, array(T_WHITESPACE, "\n", $tokens[$index]->getLine()));
}