Exemplo n.º 1
0
 /**
  * Return the whitespace previous to current token
  * Ex.: You have
  * '    if($a)'
  * if you call this funcion on 'if', you get '    '
  * @todo implements a more economic way to handle this.
  * @return   string  previous whitespace
  */
 public function getPreviousWhitespace()
 {
     $sWhiteSpace = '';
     for ($x = $this->iCount - 1; $x >= 0; $x--) {
         $this->oLog->log("sp n:{$x}", PEAR_LOG_DEBUG);
         $aToken = $this->getToken($x);
         if (is_array($aToken)) {
             if ($aToken[0] == T_WHITESPACE) {
                 $sWhiteSpace .= $aToken[1];
             } elseif (preg_match("/([\\s\r\n]+)\$/", $aToken[1], $aMatch)) {
                 $sWhiteSpace .= $aMatch[0];
                 // ArrayNested->off();
                 $this->oLog->log("+space-token-with-sp:[" . PHP_Beautifier_Common::wsToString($sWhiteSpace) . "]", PEAR_LOG_DEBUG);
                 // ArrayNested->on();
                 return $sWhiteSpace;
             }
         } else {
             $this->oLog->log("+space-token-without-sp:[" . PHP_Beautifier_Common::wsToString($sWhiteSpace) . "]", PEAR_LOG_DEBUG);
             return $sWhiteSpace;
         }
     }
     // Strange, but...
     $this->oLog->log("+space:[" . PHP_Beautifier_Common::wsToString($sWhiteSpace) . "]", PEAR_LOG_DEBUG);
     return $sWhiteSpace;
 }
 function testWsToString()
 {
     $this->assertEquals(' \\t\\r\\n', PHP_Beautifier_Common::wsToString(" \t\r\n"));
 }