From: Michael M Slusarz Date: Thu, 2 Jul 2009 18:30:32 +0000 (-0600) Subject: Add Horde_Util_Filter_Eol X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b83535b1050b513fe7395e7d26187e4cdd3db9c5;p=horde.git Add Horde_Util_Filter_Eol --- diff --git a/framework/Util/lib/Horde/Util/Filter/Eol.php b/framework/Util/lib/Horde/Util/Filter/Eol.php new file mode 100644 index 000000000..3082d21bb --- /dev/null +++ b/framework/Util/lib/Horde/Util/Filter/Eol.php @@ -0,0 +1,56 @@ + + * 'eol' - The EOL string to use. + * DEFAULT: ("\r\n") + * + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @author Michael Slusarz + * @package Horde_Util + */ +class Horde_Util_Filter_Eol extends php_user_filter +{ + protected $_search; + protected $_replace; + + public function onCreate() + { + $eol = isset($this->params['eol']) ? $this->params['eol'] : "\r\n"; + if (!strlen($eol)) { + $this->_search = array("\r", "\n"); + $this->_replace = ''; + } elseif (in_array($eol, array("\r", "\n"))) { + $this->_search = array("\r\n", ($eol == "\r") ? "\n" : "\r"); + $this->_replace = $eol; + } else { + $this->_search = array("\r\n", "\r", "\n"); + $this->_replace = array("\n", "\n", $eol); + } + + return true; + } + + public function filter($in, $out, &$consumed, $closing) + { + while ($bucket = stream_bucket_make_writeable($in)) { + $bucket->data = str_replace($this->_search, $this->_replace, $bucket->data); + $consumed += $bucket->datalen; + stream_bucket_append($out, $bucket); + } + + return PSFS_PASS_ON; + } + +} diff --git a/framework/Util/package.xml b/framework/Util/package.xml index 4318542b6..fa2fe8d54 100644 --- a/framework/Util/package.xml +++ b/framework/Util/package.xml @@ -29,7 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Removed Horde_Array::combine() and Horde_Util::hmac(). + * Added Horde_Util_Filter_Eol. + * Removed Horde_Array::combine() and Horde_Util::hmac(). * Initial Horde 4 package. @@ -41,6 +42,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + + + @@ -55,6 +61,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -96,6 +103,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/framework/Util/test/Horde/Util/eol_filter.phpt b/framework/Util/test/Horde/Util/eol_filter.phpt new file mode 100644 index 000000000..b2f55824e --- /dev/null +++ b/framework/Util/test/Horde/Util/eol_filter.phpt @@ -0,0 +1,62 @@ +--TEST-- +Horde_Util_Filter_Eol:: tests +--FILE-- + $val)); + rewind($test); + fpassthru($test); + stream_filter_remove($filter); + + echo "\n---\n"; +} + +fclose($test); +?> +--EXPECT-- +A B C D E F G H I +--- +A +B +C +D + +E + +F + +G + + +H + + +I +--- +A +B +C +D + +E + +F + +G + + +H + + +I +--- +ABCDEFGHI +---