package.xml 0000664 0001750 0001750 00000025107 12654073123 011307 0 ustar jan jan
* - string: (string) [REQUIRED] The PHP string. ** * @throws InvalidArgumentException */ public function __construct(array $opts = array()) { if (!isset($opts['string']) || !is_string($opts['string'])) { throw new InvalidArgumentException('Need a PHP string.'); } $this->stream = Horde_Stream_Wrapper_String::getStream($opts['string']); unset($opts['string']); parent::__construct($opts); } } Horde_Stream-1.6.3/lib/Horde/Stream/Temp.php 0000664 0001750 0001750 00000002726 12654073123 016673 0 ustar jan jan * @category Horde * @copyright 2012-2016 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream */ class Horde_Stream_Temp extends Horde_Stream { /** * Constructor. * * @param array $opts Additional configuration options: *
* - max_memory: (integer) The maximum amount of memory to allocate to * the PHP temporary stream. ** * @throws Horde_Stream_Exception */ public function __construct(array $opts = array()) { parent::__construct($opts); } /** * @throws Horde_Stream_Exception */ protected function _init() { $cmd = 'php://temp'; if (isset($this->_params['max_memory'])) { $cmd .= '/maxmemory:' . intval($this->_params['max_memory']); } if (($this->stream = @fopen($cmd, 'r+')) === false) { throw new Horde_Stream_Exception('Failed to open temporary memory stream.'); } } } Horde_Stream-1.6.3/lib/Horde/Stream/TempString.php 0000664 0001750 0001750 00000014125 12654073123 020056 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @since 1.6.0 * * @property-read boolean $use_stream If true, the object is using a PHP temp * stream internally. */ class Horde_Stream_TempString extends Horde_Stream_Temp { /** * String stream object. * * @var Horde_Stream_String */ protected $_string; /** */ public function __construct(array $opts = array()) { parent::__construct($opts); $temp = ''; $this->_string = new Horde_Stream_String(array( 'string' => $temp )); } /** */ protected function _init() { if (!isset($this->_params['max_memory'])) { $this->_params['max_memory'] = 2097152; } if (!$this->_string) { parent::_init(); } } /** */ public function __get($name) { switch ($name) { case 'stream': if ($this->_string) { return $this->_string->stream; } break; case 'use_stream': return !(bool)$this->_string; } return parent::__get($name); } /** */ public function __set($name, $value) { switch ($name) { case 'utf8_char': if ($this->_string) { $this->_string->utf8_char = $value; } break; } parent::__set($name, $value); } /** */ public function __clone() { if ($this->_string) { $this->_string = clone $this->_string; } else { parent::__clone(); } } /** */ public function __toString() { return $this->_string ? strval($this->_string) : parent::__toString(); } /** */ public function add($data, $reset = false) { if ($this->_string && is_string($data)) { if ((strlen($data) + $this->_string->length()) < $this->_params['max_memory']) { $this->_string->add($data, $reset); return; } parent::_init(); parent::add(strval($this->_string)); $this->seek($this->_string->pos(), false); unset($this->_string); } parent::add($data, $reset); } /** */ public function length($utf8 = false) { return $this->_string ? $this->_string->length($utf8) : parent::length($utf8); } /** */ public function getToChar($end, $all = true) { return $this->_string ? $this->_string->getToChar($end, $all) : parent::getToChar($end, $all); } /** */ public function peek($length = 1) { return $this->_string ? $this->_string->peek($length) : parent::peek($length); } /** */ public function search($char, $reverse = false, $reset = true) { return $this->_string ? $this->_string->search($char, $reverse, $reset) : parent::search($char, $reverse, $reset); } /** */ public function getString($start = null, $end = null) { return $this->_string ? $this->_string->getString($start, $end) : parent::getString($start, $end); } /** */ public function substring($start = 0, $length = null, $char = false) { return $this->_string ? $this->_string->substring($start, $length, $char) : parent::substring($start, $length, $char); } /** */ public function getChar() { return $this->_string ? $this->_string->getChar() : parent::getChar(); } /** */ public function pos() { return $this->_string ? $this->_string->pos() : parent::pos(); } /** */ public function rewind() { return $this->_string ? $this->_string->rewind() : parent::rewind(); } /** */ public function seek($offset = 0, $curr = true, $char = false) { return $this->_string ? $this->_string->seek($offset, $curr, $char) : parent::seek($offset, $curr, $char); } /** */ public function end($offset = 0) { return $this->_string ? $this->_string->end($offset) : parent::end($offset); } /** */ public function eof() { return $this->_string ? $this->_string->eof() : parent::eof(); } /* Serializable methods. */ /** */ public function serialize() { if ($this->_string) { $data = array( $this->_string, $this->_params ); } else { $data = parent::serialize(); } return serialize($data); } /** */ public function unserialize($data) { $data = unserialize($data); if ($data[0] instanceof Horde_Stream_String) { $this->_string = $data[0]; $this->_params = $data[1]; } else { parent::unserialize($data); } } } Horde_Stream-1.6.3/lib/Horde/Stream.php 0000664 0001750 0001750 00000040600 12654073123 015757 0 ustar jan jan * @category Horde * @copyright 2012-2016 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * * @property boolean $utf8_char Parse character as UTF-8 data instead of * single byte (@since 1.4.0). */ class Horde_Stream implements Serializable { /** * Stream resource. * * @var resource */ public $stream; /** * Configuration parameters. * * @var array */ protected $_params; /** * Parse character as UTF-8 data instead of single byte. * * @var boolean */ protected $_utf8_char = false; /** * Constructor. * * @param array $opts Configuration options. */ public function __construct(array $opts = array()) { $this->_params = $opts; $this->_init(); } /** * Initialization method. */ protected function _init() { // Sane default: read-write, 0-length stream. if (!$this->stream) { $this->stream = @fopen('php://temp', 'r+'); } } /** */ public function __get($name) { switch ($name) { case 'utf8_char': return $this->_utf8_char; } } /** */ public function __set($name, $value) { switch ($name) { case 'utf8_char': $this->_utf8_char = (bool)$value; break; } } /** */ public function __clone() { $data = strval($this); $this->stream = null; $this->_init(); $this->add($data); } /** * String representation of object. * * @since 1.1.0 * * @return string The full stream converted to a string. */ public function __toString() { $this->rewind(); return $this->substring(); } /** * Adds data to the stream. * * @param mixed $data Data to add to the stream. Can be a resource, * Horde_Stream object, or a string(-ish) value. * @param boolean $reset Reset stream pointer to initial position after * adding? */ public function add($data, $reset = false) { if ($reset) { $pos = $this->pos(); } if (is_resource($data)) { $dpos = ftell($data); while (!feof($data)) { $this->add(fread($data, 8192)); } fseek($data, $dpos); } elseif ($data instanceof Horde_Stream) { $dpos = $data->pos(); while (!$data->eof()) { $this->add($data->substring(0, 65536)); } $data->seek($dpos, false); } else { fwrite($this->stream, $data); } if ($reset) { $this->seek($pos, false); } } /** * Returns the length of the data. Does not change the stream position. * * @param boolean $utf8 If true, determines the UTF-8 length of the * stream (as of 1.4.0). If false, determines the * byte length of the stream. * * @return integer Stream size. * * @throws Horde_Stream_Exception */ public function length($utf8 = false) { $pos = $this->pos(); if ($utf8 && $this->_utf8_char) { $this->rewind(); $len = 0; while ($this->getChar() !== false) { ++$len; } } elseif (!$this->end()) { throw new Horde_Stream_Exception('ERROR'); } else { $len = $this->pos(); } if (!$this->seek($pos, false)) { throw new Horde_Stream_Exception('ERROR'); } return $len; } /** * Get a string up to a certain character (or EOF). * * @param string $end The character to stop reading at. As of 1.4.0, * $char can be a multi-character UTF-8 string. * @param boolean $all If true, strips all repetitions of $end from * the end. If false, stops at the first instance * of $end. (@since 1.5.0) * * @return string The string up to $end (stream is positioned after the * end character(s), all of which are stripped from the * return data). */ public function getToChar($end, $all = true) { if (($len = strlen($end)) === 1) { $out = ''; do { if (($tmp = stream_get_line($this->stream, 8192, $end)) === false) { return $out; } $out .= $tmp; if ((strlen($tmp) < 8192) || ($this->peek(-1) == $end)) { break; } } while (true); } else { $res = $this->search($end); if (is_null($res)) { return $this->substring(); } $out = substr($this->getString(null, $res + $len - 1), 0, $len * -1); } /* Remove all further characters also. */ if ($all) { while ($this->peek($len) == $end) { $this->seek($len); } } return $out; } /** * Return the current character(s) without moving the pointer. * * @param integer $length The peek length (since 1.4.0). * * @return string The current character. */ public function peek($length = 1) { $out = ''; for ($i = 0; $i < $length; ++$i) { if (($c = $this->getChar()) === false) { break; } $out .= $c; } $this->seek(strlen($out) * -1); return $out; } /** * Search for character(s) and return its position. * * @param string $char The character to search for. As of 1.4.0, * $char can be a multi-character UTF-8 string. * @param boolean $reverse Do a reverse search? * @param boolean $reset Reset the pointer to the original position? * * @return mixed The start position of the search string (integer), or * null if character not found. */ public function search($char, $reverse = false, $reset = true) { $found_pos = null; if ($len = strlen($char)) { $pos = $this->pos(); $single_char = ($len === 1); do { if ($reverse) { for ($i = $pos - 1; $i >= 0; --$i) { $this->seek($i, false); $c = $this->peek(); if ($c == ($single_char ? $char : substr($char, 0, strlen($c)))) { $found_pos = $i; break; } } } else { /* Optimization for the common use case of searching for * a single character in byte data. Reduces calling * getChar() a bunch of times. */ $fgetc = ($single_char && !$this->_utf8_char); while (($c = ($fgetc ? fgetc($this->stream) : $this->getChar())) !== false) { if ($c == ($single_char ? $char : substr($char, 0, strlen($c)))) { $found_pos = $this->pos() - ($single_char ? 1 : strlen($c)); break; } } } if ($single_char || is_null($found_pos) || ($this->getString($found_pos, $found_pos + $len - 1) == $char)) { break; } $this->seek($found_pos + ($reverse ? 0 : 1), false); $found_pos = null; } while (true); $this->seek( ($reset || is_null($found_pos)) ? $pos : $found_pos, false ); } return $found_pos; } /** * Returns the stream (or a portion of it) as a string. Position values * are the byte position in the stream. * * @param integer $start The starting position. If positive, start from * this position. If negative, starts this length * back from the current position. If null, starts * from the current position. * @param integer $end The ending position relative to the beginning of * the stream (if positive). If negative, end this * length back from the end of the stream. If null, * reads to the end of the stream. * * @return string A string. */ public function getString($start = null, $end = null) { if (!is_null($start) && ($start >= 0)) { $this->seek($start, false); $start = 0; } if (is_null($end)) { $len = null; } else { $end = ($end >= 0) ? $end - $this->pos() + 1 : $this->length() - $this->pos() + $end; $len = max($end, 0); } return $this->substring($start, $len); } /** * Return part of the stream as a string. * * @since 1.4.0 * * @param integer $start Start, as an offset from the current postion. * @param integer $length Length of string to return. If null, returns * rest of the stream. If negative, this many * characters will be omitted from the end of the * stream. * @param boolean $char If true, $start/$length is the length in * characters. If false, $start/$length is the * length in bytes. * * @return string The substring. */ public function substring($start = 0, $length = null, $char = false) { if ($start !== 0) { $this->seek($start, true, $char); } $out = ''; $to_end = is_null($length); /* If length is greater than remaining stream, use more efficient * algorithm below. Also, if doing a negative length, deal with that * below also. */ if ($char && $this->_utf8_char && !$to_end && ($length >= 0) && ($length < ($this->length() - $this->pos()))) { while ($length-- && (($char = $this->getChar()) !== false)) { $out .= $char; } return $out; } if (!$to_end && ($length < 0)) { $pos = $this->pos(); $this->end(); $this->seek($length, true, $char); $length = $this->pos() - $pos; $this->seek($pos, false); if ($length < 0) { return ''; } } while (!feof($this->stream) && ($to_end || $length)) { $read = fread($this->stream, $to_end ? 16384 : $length); $out .= $read; if (!$to_end) { $length -= strlen($read); } } return $out; } /** * Auto-determine the EOL string. * * @since 1.3.0 * * @return string The EOL string, or null if no EOL found. */ public function getEOL() { $pos = $this->pos(); $this->rewind(); $pos2 = $this->search("\n", false, false); if ($pos2) { $this->seek(-1); $eol = ($this->getChar() == "\r") ? "\r\n" : "\n"; } else { $eol = is_null($pos2) ? null : "\n"; } $this->seek($pos, false); return $eol; } /** * Return a character from the string. * * @since 1.4.0 * * @return string Character (single byte, or UTF-8 character if * $utf8_char is true). */ public function getChar() { $char = fgetc($this->stream); if (!$this->_utf8_char) { return $char; } $c = ord($char); if ($c < 0x80) { return $char; } if ($c < 0xe0) { $n = 1; } elseif ($c < 0xf0) { $n = 2; } elseif ($c < 0xf8) { $n = 3; } else { throw new Horde_Stream_Exception('ERROR'); } for ($i = 0; $i < $n; ++$i) { if (($c = fgetc($this->stream)) === false) { throw new Horde_Stream_Exception('ERROR'); } $char .= $c; } return $char; } /** * Return the current stream pointer position. * * @since 1.4.0 * * @return mixed The current position (integer), or false. */ public function pos() { return ftell($this->stream); } /** * Rewind the internal stream to the beginning. * * @since 1.4.0 * * @return boolean True if successful. */ public function rewind() { return rewind($this->stream); } /** * Move internal pointer. * * @since 1.4.0 * * @param integer $offset The offset. * @param boolean $curr If true, offset is from current position. If * false, offset is from beginning of stream. * @param boolean $char If true, $offset is the length in characters. * If false, $offset is the length in bytes. * * @return boolean True if successful. */ public function seek($offset = 0, $curr = true, $char = false) { if (!$offset) { return (bool)$curr ?: $this->rewind(); } if ($offset < 0) { if (!$curr) { return true; } elseif (abs($offset) > $this->pos()) { return $this->rewind(); } } if ($char && $this->_utf8_char) { if ($offset > 0) { if (!$curr) { $this->rewind(); } do { $this->getChar(); } while (--$offset); } else { $pos = $this->pos(); $offset = abs($offset); while ($pos-- && $offset) { fseek($this->stream, -1, SEEK_CUR); if ((ord($this->peek()) & 0xC0) != 0x80) { --$offset; } } } return true; } return (fseek($this->stream, $offset, $curr ? SEEK_CUR : SEEK_SET) === 0); } /** * Move internal pointer to the end of the stream. * * @since 1.4.0 * * @param integer $offset Move this offset from the end. * * @return boolean True if successful. */ public function end($offset = 0) { return (fseek($this->stream, $offset, SEEK_END) === 0); } /** * Has the end of the stream been reached? * * @since 1.4.0 * * @return boolean True if the end of the stream has been reached. */ public function eof() { return feof($this->stream); } /** * Close the stream. * * @since 1.4.0 */ public function close() { if ($this->stream) { fclose($this->stream); } } /* Serializable methods. */ /** */ public function serialize() { $this->_params['_pos'] = $this->pos(); return json_encode(array( strval($this), $this->_params )); } /** */ public function unserialize($data) { $this->_init(); $data = json_decode($data, true); $this->add($data[0]); $this->seek($data[1]['_pos'], false); unset($data[1]['_pos']); $this->_params = $data[1]; } } Horde_Stream-1.6.3/test/Horde/Stream/Stream/ExistingTest.php 0000664 0001750 0001750 00000001610 12654073123 022053 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @ignore * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @subpackage UnitTests */ class Horde_Stream_Stream_ExistingTest extends Horde_Stream_Stream_TestBase { protected function _getOb() { return new Horde_Stream_Existing(array( 'stream' => fopen('php://temp', 'r+') )); } } Horde_Stream-1.6.3/test/Horde/Stream/Stream/StringTest.php 0000664 0001750 0001750 00000001602 12654073123 021530 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @ignore * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @subpackage UnitTests */ class Horde_Stream_Stream_StringTest extends Horde_Stream_Stream_TestBase { protected function _getOb() { $temp = ''; return new Horde_Stream_String(array( 'string' => $temp )); } } Horde_Stream-1.6.3/test/Horde/Stream/Stream/TempStringStreamTest.php 0000664 0001750 0001750 00000002127 12654073123 023535 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @ignore * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @subpackage UnitTests */ class Horde_Stream_Stream_TempStringStreamTest extends Horde_Stream_Stream_TestBase { protected function _getOb() { return new Horde_Stream_TempString(array( 'max_memory' => 1 )); } public function testUsingStream() { $ob = $this->_getOb(); $ob->add('123'); $this->assertTrue($ob->use_stream); } } Horde_Stream-1.6.3/test/Horde/Stream/Stream/TempStringTest.php 0000664 0001750 0001750 00000002765 12654073123 022371 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @ignore * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @subpackage UnitTests */ class Horde_Stream_Stream_TempStringTest extends Horde_Stream_Stream_TestBase { protected function _getOb() { return new Horde_Stream_TempString(); } public function testNotUsingStream() { $ob = $this->_getOb(); $ob->add('123'); $this->assertFalse($ob->use_stream); } public function testMaxMemory() { $ob = new Horde_Stream_TempString(array('max_memory' => 1)); $ob->add('abcdefg'); $this->assertTrue($ob->use_stream); $this->assertEquals('abcdefg', $ob->__toString()); $ob = new Horde_Stream_TempString(array('max_memory' => 10)); $ob->add('abcd'); $this->assertFalse($ob->use_stream); $this->assertEquals('abcd', $ob->__toString()); } } Horde_Stream-1.6.3/test/Horde/Stream/Stream/TempTest.php 0000664 0001750 0001750 00000001472 12654073123 021174 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @ignore * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @subpackage UnitTests */ class Horde_Stream_Stream_TempTest extends Horde_Stream_Stream_TestBase { protected function _getOb() { return new Horde_Stream_Temp(); } } Horde_Stream-1.6.3/test/Horde/Stream/Stream/TestBase.php 0000664 0001750 0001750 00000034522 12654073123 021143 0 ustar jan jan * @category Horde * @copyright 2014-2016 Horde LLC * @ignore * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Stream * @subpackage UnitTests */ abstract class Horde_Stream_Stream_TestBase extends Horde_Test_Case { abstract protected function _getOb(); public function testPos() { $stream = $this->_getOb(); $stream->add('123'); $this->assertEquals( 3, $stream->pos() ); } public function testRewind() { $stream = $this->_getOb(); $stream->add('123'); $this->assertTrue($stream->rewind()); $this->assertEquals( 0, $stream->pos() ); } public function testSeek() { $stream = $this->_getOb(); $stream->add('123'); $this->assertTrue($stream->seek(-2)); $this->assertEquals( 1, $stream->pos() ); $this->assertTrue($stream->seek(1)); $this->assertEquals( 2, $stream->pos() ); $this->assertTrue($stream->seek(1, false)); $this->assertEquals( 1, $stream->pos() ); $this->assertTrue($stream->seek(-10)); $this->assertEquals( 0, $stream->pos() ); $stream->seek(2); $this->assertTrue($stream->seek(-10, true)); $this->assertEquals( 0, $stream->pos() ); $stream2 = $this->_getOb(); $stream2->add('Aönön'); $stream2->utf8_char = true; $stream2->rewind(); $this->assertTrue($stream2->seek(2)); $this->assertEquals( 2, $stream2->pos() ); $this->assertTrue($stream2->seek(2)); $this->assertEquals( 4, $stream2->pos() ); $this->assertTrue($stream2->seek(2, false)); $this->assertEquals( 2, $stream2->pos() ); $this->assertTrue($stream2->seek(2, false, true)); $this->assertEquals( 3, $stream2->pos() ); $this->assertTrue($stream2->seek(2, true, true)); $this->assertEquals( 6, $stream2->pos() ); $this->assertTrue($stream2->seek(-2, true, true)); $this->assertEquals( 3, $stream2->pos() ); $this->assertTrue($stream2->seek(-10, true, true)); $this->assertEquals( 0, $stream2->pos() ); } public function testEnd() { $stream = $this->_getOb(); $stream->add('123'); $stream->rewind(); $this->assertTrue($stream->end()); $this->assertEquals( 3, $stream->pos() ); } public function testEof() { $stream = $this->_getOb(); $stream->add('123'); $this->assertFalse($stream->eof()); $stream->getChar(); $this->assertTrue($stream->eof()); } public function testGetToChar() { $stream = $this->_getOb(); $stream->add('A B', true); $this->assertEquals( 'A', $stream->getToChar(' ') ); $this->assertEquals( 'B', $stream->getToChar(' ') ); $this->assertEquals( '', $stream->getToChar(' ') ); $stream2 = $this->_getOb(); $stream2->add('A B ', true); $this->assertEquals( 'A', $stream2->getToChar(' ') ); $this->assertEquals( 'B', $stream2->getToChar(' ') ); $this->assertEquals( '', $stream2->getToChar(' ') ); $stream3 = $this->_getOb(); $stream3->add("A\n\n\nB\n", true); $this->assertEquals( 'A', $stream3->getToChar("\n") ); $this->assertEquals( 'B', $stream3->getToChar("\n") ); $this->assertEquals( '', $stream3->getToChar("\n") ); $stream3->rewind(); $this->assertEquals( 'A', $stream3->getToChar("\n", false) ); $this->assertEquals( '', $stream3->getToChar("\n", false) ); $this->assertEquals( '', $stream3->getToChar("\n", false) ); $this->assertEquals( 'B', $stream3->getToChar("\n", false) ); $this->assertEquals( '', $stream3->getToChar("\n", false) ); $long_string = str_repeat('A', 15000); $stream4 = $this->_getOb(); $stream4->add($long_string . "B\n", true); $this->assertEquals( $long_string, $stream4->getToChar('B', false) ); $stream4->rewind(); $this->assertEquals( $long_string . "B", $stream4->getToChar("\n", false) ); $stream4->rewind(); $this->assertEquals( $long_string, $stream4->getToChar("B\n", false) ); } public function testLength() { $stream = $this->_getOb(); $stream->add('A B '); $this->assertEquals( 4, $stream->length() ); $this->assertFalse($stream->getChar()); $stream->rewind(); $this->assertEquals( 4, $stream->length() ); $this->assertEquals( 'A', $stream->getChar() ); } public function testGetString() { $stream = $this->_getOb(); $stream->add('A B C'); $this->assertEquals( '', $stream->getString() ); $this->assertEquals( 'A B C', $stream->getString(0) ); $stream->rewind(); $this->assertEquals( 'A B C', $stream->getString() ); $this->assertEquals( 'A B C', $stream->getString(0) ); $stream->seek(2, false); $this->assertEquals( 'B C', $stream->getString() ); $stream->seek(2, false); $this->assertEquals( 'B', $stream->getString(null, -2) ); $stream->end(); $this->assertEquals( '', $stream->getString(null, -1) ); } public function testPeek() { $stream = $this->_getOb(); $stream->add('A B', true); $this->assertEquals( 'A', $stream->peek() ); $this->assertEquals( 'A', $stream->getChar() ); $stream->end(-1); $this->assertEquals( 'B', $stream->peek() ); $this->assertEquals( 'B', $stream->getChar() ); $stream->rewind(); $this->assertEquals( 'A ', $stream->peek(2) ); $this->assertEquals( 'A', $stream->getChar() ); } public function testSearch() { $stream = $this->_getOb(); $stream->add('0123456789', true); $this->assertEquals( 5, $stream->search(5) ); $this->assertEquals( 8, $stream->search(8) ); $this->assertEquals( 3, $stream->search(3) ); $this->assertEquals( 0, $stream->pos() ); $this->assertEquals( 5, $stream->search(5, false, false) ); $this->assertEquals( 8, $stream->search(8, false, false) ); $this->assertNull($stream->search(3, false, false)); $this->assertEquals( 3, $stream->search(3, true) ); $this->assertEquals( 8, $stream->pos() ); $this->assertEquals( 3, $stream->search(3, true, false) ); $this->assertEquals( 3, $stream->pos() ); $stream->rewind(); $this->assertEquals( 3, $stream->search('34') ); $this->assertNull($stream->search('35')); } public function testAddMethod() { $stream = $this->_getOb(); $stream->add('foo'); $this->assertEquals( 3, $stream->length() ); $this->assertEquals( 'foo', $stream->getString(0) ); $stream->rewind(); $stream2 = $this->_getOb(); $stream2->add($stream, true); $this->assertEquals( 3, $stream2->length() ); $this->assertEquals( 'foo', $stream2->getString() ); $this->assertEquals( 'foo', $stream2->getString(0) ); $stream->rewind(); $stream3 = $this->_getOb(); $stream3->add($stream); $this->assertEquals( 3, $stream3->length() ); $this->assertEquals( '', $stream3->getString() ); $this->assertEquals( 'foo', $stream3->getString(0) ); } public function testStringRepresentation() { $stream = $this->_getOb(); $stream->add('123'); $this->assertEquals( '123', strval($stream) ); } public function testSerializing() { $stream = $this->_getOb(); $stream->add('123'); $stream2 = unserialize(serialize($stream)); $this->assertEquals( '123', strval($stream2) ); } public function testClone() { $stream = $this->_getOb(); $stream->add('123'); $stream2 = clone $stream; $stream->close(); $this->assertEquals( '123', strval($stream2) ); } public function testEolDetection() { $stream = $this->_getOb(); $stream->add("123\n456"); $this->assertEquals( "\n", $stream->getEOL() ); $stream = $this->_getOb(); $stream->add("123\r\n456"); $this->assertEquals( "\r\n", $stream->getEOL() ); $stream = $this->_getOb(); $stream->add("123456"); $this->assertNull($stream->getEOL()); $stream = $this->_getOb(); $stream->add("\n123456\n"); $this->assertEquals( "\n", $stream->getEOL() ); } public function testUtf8Parsing() { $test = 'Aönön'; $stream = $this->_getOb(); $stream->add($test, true); $this->assertEquals( 7, $stream->length() ); $this->assertEquals( 'A', $stream->getToChar('ö') ); $stream = $this->_getOb(); $stream->add($test, true); $stream->utf8_char = true; $this->assertEquals( 5, $stream->length(true) ); $this->assertEquals( 'Aö', $stream->getToChar('n') ); $stream->rewind(); $this->assertEquals( 'Aö', $stream->peek(2) ); $this->assertEquals( 'A', $stream->getChar() ); $stream->rewind(); $this->assertEquals( 1, $stream->search('ön') ); $stream->end(); $this->assertEquals( 4, $stream->search('ön', true) ); } public function testParsingAnExistingStreamObject() { $stream = $this->_getOb(); // 100000 byte stream. $stream->add(str_repeat('1234567890', 10000)); $stream->rewind(); $this->assertEquals( 100000, $stream->length() ); $stream2 = $this->_getOb(); $stream2->add($stream); $this->assertEquals( 100000, $stream2->length() ); } public function testSubstring() { $stream = $this->_getOb(); $stream->add('1234567890'); $stream->rewind(); $this->assertEquals( '123', $stream->substring(0, 3) ); $this->assertEquals( '456', $stream->substring(0, 3) ); $this->assertEquals( '7890', $stream->substring(0) ); $this->assertEquals( '', $stream->substring(0, 3) ); $stream->rewind(); $this->assertEquals( '456', $stream->substring(3, 3) ); $this->assertEquals( '', $stream->substring(10, 3) ); $stream->rewind(); $this->assertEquals( '123', $stream->substring(-3, 3) ); $this->assertEquals( '123', $stream->substring(-3, 3) ); $stream2 = $this->_getOb(); $stream2->add('AönönAönön'); $stream2->utf8_char = true; $stream2->rewind(); $this->assertEquals( 'Aö', $stream2->substring(0, 3) ); $stream2->rewind(); $this->assertEquals( 'Aön', $stream2->substring(0, 3, true) ); $stream2->rewind(); $this->assertEquals( 'AönönAönön', $stream2->substring(0, null, true) ); $stream2->rewind(); $this->assertEquals( 'Aönön', $stream2->substring(5, null, true) ); } } Horde_Stream-1.6.3/test/Horde/Stream/AllTests.php 0000664 0001750 0001750 00000000132 12654073123 017717 0 ustar jan jan run(); Horde_Stream-1.6.3/test/Horde/Stream/bootstrap.php 0000664 0001750 0001750 00000000143 12654073123 020203 0 ustar jan jan