[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: TabToSpaces.php 3076 2006-12-18 08:52:12Z fabien $ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information please see 20 * <http://phing.info>. 21 */ 22 23 require_once 'phing/filters/BaseParamFilterReader.php'; 24 require_once 'phing/filters/ChainableReader.php'; 25 26 /** 27 * Converts tabs to spaces. 28 * 29 * Example: 30 * 31 * <pre><tabtospaces tablength="8"></pre> 32 * 33 * Or: 34 * 35 * <pre><filterreader classname="phing.filters.TabsToSpaces"> 36 * <param name="tablength" value="8"> 37 * </filterreader></pre> 38 * 39 * @author Yannick Lecaillez <yl@seasonfive.com> 40 * @author Hans Lellelid <hans@xmpl.org> 41 * @version $Revision: 1.9 $ 42 * @see BaseParamFilterReader 43 * @package phing.filters 44 */ 45 class TabToSpaces extends BaseParamFilterReader implements ChainableReader { 46 47 /** 48 * The default tab length. 49 * @var int 50 */ 51 const DEFAULT_TAB_LENGTH = 8; 52 53 /** 54 * Parameter name for the length of a tab. 55 * @var string 56 */ 57 const TAB_LENGTH_KEY = "tablength"; 58 59 /** 60 * Tab length in this filter. 61 * @var int 62 */ 63 private $tabLength = 8; //self::DEFAULT_TAB_LENGTH; 64 65 /** 66 * Returns stream after converting tabs to the specified number of spaces. 67 * 68 * @return the resulting stream, or -1 69 * if the end of the resulting stream has been reached 70 * 71 * @exception IOException if the underlying stream throws an IOException 72 * during reading 73 */ 74 function read($len = null) { 75 76 if ( !$this->getInitialized() ) { 77 $this->_initialize(); 78 $this->setInitialized(true); 79 } 80 81 $buffer = $this->in->read($len); 82 83 if($buffer === -1) { 84 return -1; 85 } 86 87 $buffer = str_replace("\t", str_repeat(' ', $this->tabLength), $buffer); 88 89 return $buffer; 90 } 91 92 /** 93 * Sets the tab length. 94 * 95 * @param int $tabLength The number of spaces to be used when converting a tab. 96 */ 97 function setTablength($tabLength) { 98 $this->tabLength = (int) $tabLength; 99 } 100 101 /** 102 * Returns the tab length. 103 * 104 * @return int The number of spaces used when converting a tab 105 */ 106 function getTablength() { 107 return $this->tabLength; 108 } 109 110 /** 111 * Creates a new TabsToSpaces using the passed in 112 * Reader for instantiation. 113 * 114 * @param Reader $reader A Reader object providing the underlying stream. 115 * Must not be <code>null</code>. 116 * 117 * @return Reader A new filter based on this configuration, but filtering 118 * the specified reader 119 */ 120 function chain(Reader $reader) { 121 $newFilter = new TabToSpaces($reader); 122 $newFilter->setTablength($this->getTablength()); 123 $newFilter->setInitialized(true); 124 $newFilter->setProject($this->getProject()); 125 return $newFilter; 126 } 127 128 /** 129 * Parses the parameters to set the tab length. 130 */ 131 private function _initialize() { 132 $params = $this->getParameters(); 133 if ( $params !== null ) { 134 for($i = 0 ; $i<count($params) ; $i++) { 135 if (self::TAB_LENGTH_KEY === $params[$i]->getName()) { 136 $this->tabLength = $params[$i]->getValue(); 137 break; 138 } 139 } 140 } 141 } 142 } 143 144 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |