[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/filters/ -> StripLineBreaks.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: StripLineBreaks.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  include_once 'phing/filters/BaseParamFilterReader.php';
  24  include_once 'phing/filters/ChainableReader.php';
  25  
  26  /**
  27   * Filter to flatten the stream to a single line.
  28   * 
  29   * Example:
  30   *
  31   * <pre><striplinebreaks/></pre>
  32   *
  33   * Or:
  34   *
  35   * <pre><filterreader classname="phing.filters.StripLineBreaks"/></pre>
  36   *
  37   * @author    <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
  38   * @author    hans lellelid, hans@velum.net
  39   * @version   $Revision: 1.8 $ $Date: 2004/03/15 14:45:06 $
  40   * @access    public
  41   * @see       BaseParamFilterReader
  42   * @package   phing.filters
  43   */
  44  class StripLineBreaks extends BaseParamFilterReader implements ChainableReader {
  45  
  46      /**
  47       * Default line-breaking characters.
  48       * @var string
  49       */
  50      const DEFAULT_LINE_BREAKS = "\r\n";
  51      
  52      /**
  53       * Parameter name for the line-breaking characters parameter.
  54       * @var string
  55       */
  56      const LINES_BREAKS_KEY = "linebreaks";
  57      
  58      /**
  59       * The characters that are recognized as line breaks.
  60       * @var string
  61       */ 
  62      private    $_lineBreaks = "\r\n"; // self::DEFAULT_LINE_BREAKS;
  63   
  64      /**
  65       * Returns the filtered stream, only including
  66       * characters not in the set of line-breaking characters.
  67       * 
  68       * @return mixed    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          if ( !$this->getInitialized() ) {
  76              $this->_initialize();
  77              $this->setInitialized(true);
  78          }
  79  
  80          $buffer = $this->in->read($len);
  81          if($buffer === -1) {
  82              return -1;
  83          }
  84          
  85          $buffer = preg_replace("/[".$this->_lineBreaks."]/", '', $buffer);           
  86  
  87          return $buffer;
  88      }
  89      
  90       /**
  91       * Sets the line-breaking characters.
  92       * 
  93       * @param string $lineBreaks A String containing all the characters to be
  94       *                   considered as line-breaking.
  95       */
  96      function setLineBreaks($lineBreaks) {
  97          $this->_lineBreaks = (string) $lineBreaks;
  98      }
  99  
 100      /**
 101       * Gets the line-breaking characters.
 102       * 
 103       * @return string A String containing all the characters that are considered as line-breaking.
 104       */ 
 105      function getLineBreaks() {
 106          return $this->_lineBreaks;
 107      }
 108  
 109      /**
 110       * Creates a new StripLineBreaks using the passed in
 111       * Reader for instantiation.
 112       * 
 113       * @param object A Reader object providing the underlying stream.
 114       *               Must not be <code>null</code>.
 115       * 
 116       * @return object A new filter based on this configuration, but filtering
 117       *         the specified reader
 118       */
 119      function chain(Reader $reader) {
 120          $newFilter = new StripLineBreaks($reader);
 121          $newFilter->setLineBreaks($this->getLineBreaks());
 122          $newFilter->setInitialized(true);
 123          $newFilter->setProject($this->getProject());        
 124          return $newFilter;
 125      }
 126  
 127      /**
 128       * Parses the parameters to set the line-breaking characters.
 129       */
 130      private function _initialize() {
 131          $userDefinedLineBreaks = null;
 132          $params = $this->getParameters();
 133          if ( $params !== null ) {
 134              for($i = 0 ; $i<count($params) ; $i++) {
 135                  if ( self::LINE_BREAKS_KEY === $params[$i]->getName() ) {
 136                      $userDefinedLineBreaks = $params[$i]->getValue();
 137                      break;
 138                  }
 139              }
 140          }
 141  
 142          if ( $userDefinedLineBreaks !== null ) {
 143              $this->_lineBreaks = $userDefinedLineBreaks;
 144          }
 145      }
 146  }
 147  
 148  ?>


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7