roundcubemail/program/lib/Roundcube/rcube_text2html.php
protected function _convert_line($text, $is_flowed)
    {
        static $table;

        if (empty($table)) {
            $table = get_html_translation_table(HTML_SPECIALCHARS);
            unset($table['?']);

            // replace some whitespace characters
            $table["\r"] = '';
            $table["\t"] = '    ';
        }

        // skip signature separator
        if ($text == '-- ') {
            return '--' . $this->config['space'];
        }

        // replace HTML special and whitespace characters
        $text = strtr($text, $table);

        $nbsp = $this->config['space'];

        // replace spaces with non-breaking spaces
        if ($is_flowed) {
            $pos  = 0;
            $diff = 0;
            $len  = strlen($nbsp);
            $copy = $text;

            while (($pos = strpos($text, ' ', $pos)) !== false) {
                if ($pos == 0 || $text[$pos-1] == ' ') {
                    $copy = substr_replace($copy, $nbsp, $pos + $diff, 1);
                    $diff += $len - 1;
                }
                $pos++;
            }

            $text = $copy;
        }
        // make the whole line non-breakable if needed
        else if ($text !== '' && preg_match('/[^a-zA-Z0-9_]/', $text)) {
            // use non-breakable spaces to correctly display
            // trailing/leading spaces and multi-space inside
            $text = str_replace(' ', $nbsp, $text);
            // wrap in nobr element, so it's not wrapped on e.g. - or /
            $text = $this->config['nobr_start'] . $text .  $this->config['nobr_end'];
        }

        return $text;
    }
protected function _convert_line($text, $is_flowed)
    {
        static $table;

        if (empty($table)) {
            $table = get_html_translation_table(HTML_SPECIALCHARS);
            unset($table['?']);

            // replace some whitespace characters
            $table["\r"] = '';
            $table["\t"] = '    ';
        }

        // skip signature separator
        if ($text == '-- ') {
            return '--' . $this->config['space'];
        }

        // replace HTML special and whitespace characters
        $text = strtr($text, $table);

        $nbsp = $this->config['space'];

        // replace spaces with non-breaking spaces
        if ($is_flowed) {
            $pos  = 0;
            $diff = 0;
            $len  = strlen($nbsp);
            $copy = $text;

            while (($pos = strpos($text, ' ', $pos)) !== false) {
                if ($pos == 0 || $text[$pos-1] == ' ') {
                    $copy = substr_replace($copy, $nbsp, $pos + $diff, 1);
                    $diff += $len - 1;
                }
                $pos++;
            }

            $text = $copy;
        }
        // make the whole line non-breakable if needed
        else if ($text !== '' && preg_match('/[^a-zA-Z0-9_]/', $text)) {
            // use non-breakable spaces to correctly display
            // trailing/leading spaces and multi-space inside
            $text = str_replace(' ', $nbsp, $text);
            // wrap in nobr element, so it's not wrapped on e.g. - or /
            $text = $this->config['nobr_start'] . $text .  $this->config['nobr_end'];
        }

        return $text;
    }
protected function _convert_line ( $ text , $ is_flowed ) { static $ table ; if ( empty ( $ table ) ) { $ table = get_html_translation_table ( HTML_SPECIALCHARS ) ; unset ( $ table [ '?' ] ) ; // replace some whitespace characters $ table [ "\r" ] = '' ; $ table [ "\t" ] = '    ' ; } // skip signature separator if ( $ text == '-- ' ) { return '--' . $ this -> config [ 'space' ] ; } // replace HTML special and whitespace characters $ text = strtr ( $ text , $ table ) ; $ nbsp = $ this -> config [ 'space' ] ; // replace spaces with non-breaking spaces if ( $ is_flowed ) { $ pos = 0 ; $ diff = 0 ; $ len = strlen ( $ nbsp ) ; $ copy = $ text ; while ( ( $ pos = strpos ( $ text , ' ' , $ pos ) ) !== false ) { if ( $ pos == 0 || $ text [ $ pos - 1 ] == ' ' ) { $ copy = substr_replace ( $ copy , $ nbsp , $ pos + $ diff , 1 ) ; $ diff += $ len - 1 ; } $ pos ++ ; } $ text = $ copy ; } // make the whole line non-breakable if needed else if ( $ text !== '' && preg_match ( '/[^a-zA-Z0-9_]/' , $ text ) ) { // use non-breakable spaces to correctly display // trailing/leading spaces and multi-space inside $ text = str_replace ( ' ' , $ nbsp , $ text ) ; // wrap in nobr element, so it's not wrapped on e.g. - or / $ text = $ this -> config [ 'nobr_start' ] . $ text . $ this -> config [ 'nobr_end' ] ; } return $ text ; }
Converts spaces in line of text
Converts spaces in line of text