StringReader.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * $Id: StringReader.php 905 2010-10-05 16:28:03Z mrook $
  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. * Dummy class for reading from string of characters.
  23. * @package phing.system.io
  24. */
  25. class StringReader extends Reader {
  26. /**
  27. * @var string
  28. */
  29. private $_string;
  30. /**
  31. * @var int
  32. */
  33. private $mark = 0;
  34. /**
  35. * @var int
  36. */
  37. private $currPos = 0;
  38. function __construct($string) {
  39. $this->_string = $string;
  40. }
  41. function skip($n) {}
  42. function read($len = null) {
  43. if ($len === null) {
  44. return $this->_string;
  45. } else {
  46. if ($this->currPos >= strlen($this->_string)) {
  47. return -1;
  48. }
  49. $out = substr($this->_string, $this->currPos, $len);
  50. $this->currPos += $len;
  51. return $out;
  52. }
  53. }
  54. function mark() {
  55. $this->mark = $this->currPos;
  56. }
  57. function reset() {
  58. $this->currPos = $this->mark;
  59. }
  60. function close() {}
  61. function open() {}
  62. function ready() {}
  63. function markSupported() {
  64. return true;
  65. }
  66. function getResource() {
  67. return '(string) "'.$this->_string . '"';
  68. }
  69. }