home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / system / io / StringReader.php < prev    next >
Encoding:
PHP Script  |  2007-08-28  |  2.1 KB  |  85 lines

  1. <?php
  2. /*
  3.  *  $Id: StringReader.php 227 2007-08-28 02:17:00Z hans $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information please see
  19.  * <http://phing.info>. 
  20.  */
  21.  
  22. /**
  23.  * Dummy class for reading from string of characters. 
  24.  * @package phing.system.io
  25.  */
  26. class StringReader extends Reader {
  27.     
  28.     /**
  29.      * @var string
  30.      */
  31.     private $_string;
  32.     
  33.     /**
  34.      * @var int
  35.      */
  36.     private $mark = 0;
  37.     
  38.     /**
  39.      * @var int
  40.      */
  41.     private $currPos = 0;
  42.     
  43.     function __construct($string) {
  44.         $this->_string = $string;
  45.     }
  46.  
  47.     function skip($n) {}
  48.  
  49.     function read($len = null) {
  50.         if ($len === null) {
  51.             return $this->_string;
  52.         } else {            
  53.             if ($this->currPos >= strlen($this->_string)) {
  54.                 return -1;
  55.             }            
  56.             $out = substr($this->_string, $this->currPos, $len);
  57.             $this->currPos += $len;
  58.             return $out;
  59.         }
  60.     }
  61.  
  62.     function mark() {
  63.         $this->mark = $this->currPos;
  64.     }
  65.  
  66.     function reset() {
  67.         $this->currPos = $this->mark;
  68.     }
  69.  
  70.     function close() {}
  71.  
  72.     function open() {}
  73.  
  74.     function ready() {}
  75.  
  76.     function markSupported() {
  77.         return true;
  78.     }
  79.     
  80.     function getResource() {
  81.         return '(string) "'.$this->_string . '"';
  82.     }
  83. }
  84. ?>
  85.