Changeset b214f8d in github


Ignore:
Timestamp:
Oct 14, 2008 9:32:48 AM (5 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
b92a674
Parents:
32eb29f
Message:

#1485398, #1485441: fix (p)spell checking CRLF/multibyte issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/steps/mail/spell_pspell.inc

    r81308b3 rb214f8d  
    3030} 
    3131 
     32// read input 
    3233$data = file_get_contents('php://input'); 
    33 $xml = simplexml_load_string($data); 
    34 $text = (string)$xml->text; 
     34 
     35// parse data (simplexml_load_string breaks CRLFs) 
     36$left = strpos($data, '<text>'); 
     37$right = strrpos($data, '</text>'); 
     38$text = substr($data, $left+6, $right-($left+6)); 
     39 
     40// tokenize 
    3541$words = preg_split('/[ !"#$%&()*+\\,-.\/\n:;<=>?@\[\]^_{|}]+/', $text, NULL,  PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE ); 
    36 $plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, 'utf-8'); 
     42 
     43// init spellchecker 
     44$plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, 'utf-8', PSPELL_FAST); 
     45 
     46// send output 
    3747$out = '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="'.rc_strlen($text).'">'; 
    3848 
    3949$diff = 0; 
    4050foreach ($words as $w) { 
    41     $word = $w[0]; 
     51    $word = trim($w[0]); 
    4252    $pos  = $w[1] - $diff; 
    4353    $len  = rc_strlen($word); 
    44     if ($plink && !pspell_check($plink, $word)) { 
     54    if ($word && $plink && !pspell_check($plink, $word)) { 
    4555        $suggestions = pspell_suggest($plink, $word); 
    4656        $out .= '<c o="'.$pos.'" l="'.$len.'">'; 
     
    5060    $diff += (strlen($word) - $len); 
    5161} 
     62 
    5263$out .= '</spellresult>'; 
    5364 
Note: See TracChangeset for help on using the changeset viewer.