Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (61)

View Page History

{zone-data:component-name}
Zend_Filter_ConvertNewlines Zend_Filter_Newline
{zone-data}

{zone-data:proposer-list}
[Pawe? Przeradowski|mailto:showerproof86@gmail]
[~thomas]
{zone-data}


{zone-data:revision}
0.1 - 10 August 2008: Initial Draft.
1.0 - 8 August 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Filter_ConvertNewlines Zend_Filter_Newline is a filter that which handles conversion between various line termination styles used on different architectures.
{zone-data}

{zone-data:references}
* [Wikipedia Entry on Newline|http://en.wikipedia.org/wiki/Newline]
* [Prototype of previous proposal here - works slightly different than this proposal|http://code.google.com/p/zfunixtoolchain/source/browse/trunk/unix-toolchain/library/Zend/Filter/ConvertNewlines.php]
{zone-data}

{zone-data:requirements}

* This component *will* support Windows, Unix, Mac, Native and custom line terminators
* This component *will* be as simple as possible. also support Unicode line terminators
* This component *will* support Windows, Unix, Mac, Native and custom line terminators.
* This component *will* allow to replace newlines with arbitrary text.
{zone-data}

{zone-data:dependencies}
* Zend_Filter_Interface
* Zend_View_Helper_Newline
{zone-data}

{zone-data:operation}
The component operate as each other Zend_Filter_*. It is typically used in filter chains together with other filters. It can also be used alone.
Zend_Filter_Newline is a filter which can change/filter newlines of given strings. It takes also care of unicode line terminators. For simplicity this filter also adds a view helper which makes use of this filter.
{zone-data}

{zone-data:milestones}
* Milestone 1: Initial design notes and interface \[DONE\]
* Milestone 2: Working prototype checked into [here|http://code.google.com/p/zfunixtoolchain/source/browse/trunk/unix-toolchain/library/Zend/Filter/ConvertNewlines.php] \[DONE\]
* Milestone 3: Working prototype checked into the incubator supporting use cases #1 and #2.
* Milestone 1: *\[DONE\]* Proposal finished
* Milestone 2: Proposal accepted
* Milestone 3: Working implementation
* Milestone 4: Unit tests exist, work, and are checked into SVN.
* Milestone 5: Initial documentation exists. Documentation

* Milestone 6: Moved to core
{zone-data}

{zone-data:class-list}
* Zend_Filter_ConvertNewlines Zend_Filter_Newline
* Zend_View_Helper_Newline
{zone-data}

{zone-data:use-cases}
||UC-01: Converting Mac-style into Windows-style||

{code:php}
$convert = new Zend_Filter_ConvertNewlines('windows');

$a = "a\rb\r";
$b = $convert->filter($a);

var_dump(array_map('ord', str_split($b)));
||UC-01||
Converting Mac to Windows
{code}
$filter = new Zend_Filter_Newline(array('delimiter' => Zend_Filter_Newline::WINDOWS));

Output: $filter->filter("a\rb\r");
{code:php}
array(6) {
[0] => int(97)
[1] => int(13)
[2] => int(10)
[3] => int(98)
[4] => int(13)
[5] => int(10)
}
// returns a\r\nb\r\n
{code}

||UC-02||
||UC-02: Converting Windows-style into '<br />'s||

{code:php}
$convert = new Zend_Filter_ConvertNewlines(null, '<br />');

$a = "abc\r\ndef\r\n";
$b = $convert->filter($a);

echo $b;
{code}
$filter = new Zend_Filter_Newline(array('delimiter' => '<br />'));

Output: $filter->filter("abc\r\ndef\r\n");
{code:html}
// returns abc<br />def<br />
{code}

{zone-data}

{zone-data:skeletons}
{code:php}
class Zend_Filter_ConvertNewlines Zend_Filter_Newline implements Zend_Filter_Interface
{
/** const NATIVE;
* Predefined line termination styles.
*/ const WINDOWS;
const STYLE_WINDOWS = 'WINDOWS'; UNIX;
const STYLE_UNIX = 'UNIX'; MAC;
const STYLE_MAC = 'MAC'; NEXTLINE;
const STYLE_NATIVE = 'NATIVE'; FORMFEED;

/** const LINESEPARATOR
* The delimiter string this filter uses for line termination.
* const FORMSEPARATOR
* @var string const ALL
*/
private $_delimiter = null;

/**
* Initialize Zend_Filter_Newlines object.
*
* @param string $style Predefined line terminatiln styles. One of STYLE_* constants.
* @param string $delimiter Custom string line delimiter.
*/
public function __construct($style, $delimiter = null)
{
}

/**
* Sets line termination style.
* public function __construct($options)
* @param string $style Predefined line terminatiln styles. One of STYLE_* constants.
* @param string $delimiter Custom string line delimiter.
*
* @return Zend_Filter_ConvertNewlines Provides fluent interface
*/
public function setStyle($style, $delimiter setDelimiter($delimiter = null)
{
}

/**
* Returns line delimiter string used by this filter.
*
* @return string Line delimiter string
*/
public function getDelimiter()
{
}

/**
* Declared in Zend_Filter_Interface
*
* Returns the string $value with line delimiters converted into chosen style.
*
* @param string $value
* @return string
*/
public function filter($value)
{
}
}

class Zend_View_Helper_Newline implements Zend_View_Helper_Abstract
{
public newline($value);
}
{code}
{zone-data}