private function _splitText($data, &$result)
    {
        $raw_paragraphs = explode("\n\n", $data);
        $paragraphs = array(); // without empty paragraphs
        $needs_start = false;
        $needs_end = false;

        $c = count($raw_paragraphs);
        if ($c == 1) {
            // There were no double-newlines, abort quickly. In theory this
            // should never happen.
            $result[] = new HTMLPurifier_Token_Text($data);
            return;
        }
        for ($i = 0; $i < $c; $i++) {
            $par = $raw_paragraphs[$i];
            if (trim($par) !== '') {
                $paragraphs[] = $par;
            } else {
                if ($i == 0) {
                    // Double newline at the front
                    if (empty($result)) {
                        // The empty result indicates that the AutoParagraph
                        // injector did not add any start paragraph tokens.
                        // This means that we have been in a paragraph for
                        // a while, and the newline means we should start a new one.
                        $result[] = new HTMLPurifier_Token_End('p');
                        $result[] = new HTMLPurifier_Token_Text("\n\n");
                        // However, the start token should only be added if
                        // there is more processing to be done (i.e. there are
                        // real paragraphs in here). If there are none, the
                        // next start paragraph tag will be handled by the
                        // next call to the injector
                        $needs_start = true;
                    } else {
                        // We just started a new paragraph!
                        // Reinstate a double-newline for presentation's sake, since
                        // it was in the source code.
                        array_unshift($result, new HTMLPurifier_Token_Text("\n\n"));
                    }
                } elseif ($i + 1 == $c) {
                    // Double newline at the end
                    // There should be a trailing </p> when we're finally done.
                    $needs_end = true;
                }
            }
        }

        // Check if this was just a giant blob of whitespace. Move this earlier,
        // perhaps?
        if (empty($paragraphs)) {
            return;
        }

        // Add the start tag indicated by \n\n at the beginning of $data
        if ($needs_start) {
            $result[] = $this->_pStart();
        }

        // Append the paragraphs onto the result
        foreach ($paragraphs as $par) {
            $result[] = new HTMLPurifier_Token_Text($par);
            $result[] = new HTMLPurifier_Token_End('p');
            $result[] = new HTMLPurifier_Token_Text("\n\n");
            $result[] = $this->_pStart();
        }

        // Remove trailing start token; Injector will handle this later if
        // it was indeed needed. This prevents from needing to do a lookahead,
        // at the cost of a lookbehind later.
        array_pop($result);

        // If there is no need for an end tag, remove all of it and let
        // MakeWellFormed close it later.
        if (!$needs_end) {
            array_pop($result); // removes \n\n
            array_pop($result); // removes </p>
        }
    }
private function _splitText($data, &$result)
    {
        $raw_paragraphs = explode("\n\n", $data);
        $paragraphs = array(); // without empty paragraphs
        $needs_start = false;
        $needs_end = false;

        $c = count($raw_paragraphs);
        if ($c == 1) {
            // There were no double-newlines, abort quickly. In theory this
            // should never happen.
            $result[] = new HTMLPurifier_Token_Text($data);
            return;
        }
        for ($i = 0; $i < $c; $i++) {
            $par = $raw_paragraphs[$i];
            if (trim($par) !== '') {
                $paragraphs[] = $par;
            } else {
                if ($i == 0) {
                    // Double newline at the front
                    if (empty($result)) {
                        // The empty result indicates that the AutoParagraph
                        // injector did not add any start paragraph tokens.
                        // This means that we have been in a paragraph for
                        // a while, and the newline means we should start a new one.
                        $result[] = new HTMLPurifier_Token_End('p');
                        $result[] = new HTMLPurifier_Token_Text("\n\n");
                        // However, the start token should only be added if
                        // there is more processing to be done (i.e. there are
                        // real paragraphs in here). If there are none, the
                        // next start paragraph tag will be handled by the
                        // next call to the injector
                        $needs_start = true;
                    } else {
                        // We just started a new paragraph!
                        // Reinstate a double-newline for presentation's sake, since
                        // it was in the source code.
                        array_unshift($result, new HTMLPurifier_Token_Text("\n\n"));
                    }
                } elseif ($i + 1 == $c) {
                    // Double newline at the end
                    // There should be a trailing </p> when we're finally done.
                    $needs_end = true;
                }
            }
        }

        // Check if this was just a giant blob of whitespace. Move this earlier,
        // perhaps?
        if (empty($paragraphs)) {
            return;
        }

        // Add the start tag indicated by \n\n at the beginning of $data
        if ($needs_start) {
            $result[] = $this->_pStart();
        }

        // Append the paragraphs onto the result
        foreach ($paragraphs as $par) {
            $result[] = new HTMLPurifier_Token_Text($par);
            $result[] = new HTMLPurifier_Token_End('p');
            $result[] = new HTMLPurifier_Token_Text("\n\n");
            $result[] = $this->_pStart();
        }

        // Remove trailing start token; Injector will handle this later if
        // it was indeed needed. This prevents from needing to do a lookahead,
        // at the cost of a lookbehind later.
        array_pop($result);

        // If there is no need for an end tag, remove all of it and let
        // MakeWellFormed close it later.
        if (!$needs_end) {
            array_pop($result); // removes \n\n
            array_pop($result); // removes </p>
        }
    }
private function _splitText ( $ data , & $ result ) { $ raw_paragraphs = explode ( "\n\n" , $ data ) ; $ paragraphs = array ( ) ; // without empty paragraphs
 $ needs_start = false ; $ needs_end = false ; $ c = count ( $ raw_paragraphs ) ; if ( $ c == 1 ) { // There were no double-newlines, abort quickly. In theory this
 // should never happen.
 $ result [ ] = new HTMLPurifier_Token_Text ( $ data ) ; return ; } for ( $ i = 0 ; $ i < $ c ; $ i ++ ) { $ par = $ raw_paragraphs [ $ i ] ; if ( trim ( $ par ) !== '' ) { $ paragraphs [ ] = $ par ; } else { if ( $ i == 0 ) { // Double newline at the front
 if ( empty ( $ result ) ) { // The empty result indicates that the AutoParagraph
 // injector did not add any start paragraph tokens.
 // This means that we have been in a paragraph for
 // a while, and the newline means we should start a new one.
 $ result [ ] = new HTMLPurifier_Token_End ( 'p' ) ; $ result [ ] = new HTMLPurifier_Token_Text ( "\n\n" ) ; // However, the start token should only be added if
 // there is more processing to be done (i.e. there are
 // real paragraphs in here). If there are none, the
 // next start paragraph tag will be handled by the
 // next call to the injector
 $ needs_start = true ; } else { // We just started a new paragraph!
 // Reinstate a double-newline for presentation's sake, since
 // it was in the source code.
 array_unshift ( $ result , new HTMLPurifier_Token_Text ( "\n\n" ) ) ; } } elseif ( $ i + 1 == $ c ) { // Double newline at the end
 // There should be a trailing </p> when we're finally done.
 $ needs_end = true ; } } } // Check if this was just a giant blob of whitespace. Move this earlier,
 // perhaps?
 if ( empty ( $ paragraphs ) ) { return ; } // Add the start tag indicated by \n\n at the beginning of $data
 if ( $ needs_start ) { $ result [ ] = $ this -> _pStart ( ) ; } // Append the paragraphs onto the result
 foreach ( $ paragraphs as $ par ) { $ result [ ] = new HTMLPurifier_Token_Text ( $ par ) ; $ result [ ] = new HTMLPurifier_Token_End ( 'p' ) ; $ result [ ] = new HTMLPurifier_Token_Text ( "\n\n" ) ; $ result [ ] = $ this -> _pStart ( ) ; } // Remove trailing start token; Injector will handle this later if
 // it was indeed needed. This prevents from needing to do a lookahead,
 // at the cost of a lookbehind later.
 array_pop ( $ result ) ; // If there is no need for an end tag, remove all of it and let
 // MakeWellFormed close it later.
 if ( ! $ needs_end ) { array_pop ( $ result ) ; // removes \n\n
 array_pop ( $ result ) ; // removes </p>
 } }
Splits up a text in paragraph tokens and appends them
to the result stream that will replace the original
@param string $data String text data that will be processed
into paragraphs
@param HTMLPurifier_Token[] $result Reference to array of tokens that the
tags will be appended onto
Splits up a text in paragraph tokens and appends them to the result stream that will replace the original