当前位置: 首页>>代码示例>>PHP>>正文


PHP Token::isWhitespace方法代码示例

本文整理汇总了PHP中Symfony\CS\Tokenizer\Token::isWhitespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::isWhitespace方法的具体用法?PHP Token::isWhitespace怎么用?PHP Token::isWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\CS\Tokenizer\Token的用法示例。


在下文中一共展示了Token::isWhitespace方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calculateTrailingWhitespaceIndent

 public static function calculateTrailingWhitespaceIndent(Token $token)
 {
     if (!$token->isWhitespace()) {
         throw new \InvalidArgumentException('The given token must be whitespace.');
     }
     return ltrim(strrchr(str_replace(array("\r\n", "\r"), "\n", $token->getContent()), 10), "\n");
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:7,代码来源:Utils.php

示例2: fixWhitespace

 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace(array('whitespaces' => " \t"))) {
         $token->setContent(' ');
     }
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:6,代码来源:UnalignDoubleArrowFixer.php

示例3: findSequence

 /**
  * Find a sequence of meaningful tokens and returns the array of their locations.
  *
  * @param array      $sequence      an array of tokens (same format used by getNextTokenOfKind)
  * @param int        $start         start index, defaulting to the start of the file
  * @param int        $end           end index, defaulting to the end of the file
  * @param bool|array $caseSensitive global case sensitiveness or an array of booleans, whose keys should match
  *                                  the ones used in $others. If any is missing, the default case-sensitive
  *                                  comparison is used.
  *
  * @return array|null an array containing the tokens matching the sequence elements, indexed by their position
  */
 public function findSequence(array $sequence, $start = 0, $end = null, $caseSensitive = true)
 {
     // $end defaults to the end of the collection
     if (null === $end) {
         $end = count($this) - 1;
     }
     if (!count($sequence)) {
         throw new \InvalidArgumentException('Invalid sequence');
     }
     // make sure the sequence content is "meaningful"
     foreach ($sequence as $key => $token) {
         // if not a Token instance already, we convert it to verify the meaningfulness
         if (!$token instanceof Token) {
             if (is_array($token) && !isset($token[1])) {
                 // fake some content as it is required by the Token constructor,
                 // although optional for search purposes
                 $token[1] = '';
             }
             $token = new Token($token);
         }
         if ($token->isWhitespace() || $token->isComment() || $token->isEmpty()) {
             throw new \InvalidArgumentException(sprintf('Non-meaningful token at position: %s', $key));
         }
     }
     // remove the first token from the sequence, so we can freely iterate through the sequence after a match to
     // the first one is found
     $key = key($sequence);
     $firstCs = Token::isKeyCaseSensitive($caseSensitive, $key);
     $firstToken = $sequence[$key];
     unset($sequence[$key]);
     // begin searching for the first token in the sequence (start included)
     $index = $start - 1;
     while (null !== $index && $index <= $end) {
         $index = $this->getNextTokenOfKind($index, array($firstToken), $firstCs);
         // ensure we found a match and didn't get past the end index
         if (null === $index || $index > $end) {
             return;
         }
         // initialise the result array with the current index
         $result = array($index => $this[$index]);
         // advance cursor to the current position
         $currIdx = $index;
         // iterate through the remaining tokens in the sequence
         foreach ($sequence as $key => $token) {
             $currIdx = $this->getNextMeaningfulToken($currIdx);
             // ensure we didn't go too far
             if (null === $currIdx || $currIdx > $end) {
                 return;
             }
             if (!$this[$currIdx]->equals($token, Token::isKeyCaseSensitive($caseSensitive, $key))) {
                 // not a match, restart the outer loop
                 continue 2;
             }
             // append index to the result array
             $result[$currIdx] = $this[$currIdx];
         }
         // do we have a complete match?
         // hint: $result is bigger than $sequence since the first token has been removed from the latter
         if (count($sequence) < count($result)) {
             return $result;
         }
     }
 }
开发者ID:jimlind,项目名称:PHP-CS-Fixer,代码行数:75,代码来源:Tokens.php

示例4: fixWhitespace

 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace() && !$token->isWhitespace(" \t")) {
         $token->setContent(rtrim($token->getContent()) . ' ');
     }
 }
开发者ID:skillberto,项目名称:PHP-CS-Fixer,代码行数:6,代码来源:DoubleArrowMultilineWhitespacesFixer.php

示例5: fixWhitespace

 /**
  * If given token is a single line whitespace then fix it to be a single space.
  *
  * @param Token $token
  */
 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace(" \t")) {
         $token->setContent(' ');
     }
 }
开发者ID:skillberto,项目名称:PHP-CS-Fixer,代码行数:11,代码来源:UnalignDoubleArrowFixer.php

示例6: findSequence

 public function findSequence(array $sequence, $start = 0, $end = null, $caseSensitive = true)
 {
     if (null === $end) {
         $end = count($this) - 1;
     }
     if (!count($sequence)) {
         throw new \InvalidArgumentException('Invalid sequence');
     }
     foreach ($sequence as $key => $token) {
         if (!$token instanceof Token) {
             if (is_array($token) && !isset($token[1])) {
                 $token[1] = '';
             }
             $token = new Token($token);
         }
         if ($token->isWhitespace() || $token->isComment() || $token->isEmpty()) {
             throw new \InvalidArgumentException(sprintf('Non-meaningful token at position: %s', $key));
         }
     }
     $key = key($sequence);
     $firstCs = Token::isKeyCaseSensitive($caseSensitive, $key);
     $firstToken = $sequence[$key];
     unset($sequence[$key]);
     $index = $start - 1;
     while (null !== $index && $index <= $end) {
         $index = $this->getNextTokenOfKind($index, array($firstToken), $firstCs);
         if (null === $index || $index > $end) {
             return;
         }
         $result = array($index => $this[$index]);
         $currIdx = $index;
         foreach ($sequence as $key => $token) {
             $currIdx = $this->getNextMeaningfulToken($currIdx);
             if (null === $currIdx || $currIdx > $end) {
                 return;
             }
             if (!$this[$currIdx]->equals($token, Token::isKeyCaseSensitive($caseSensitive, $key))) {
                 continue 2;
             }
             $result[$currIdx] = $this[$currIdx];
         }
         if (count($sequence) < count($result)) {
             return $result;
         }
     }
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:46,代码来源:Tokens.php


注:本文中的Symfony\CS\Tokenizer\Token::isWhitespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。