diff options
author | matthiasgrimm <matthiasgrimm@users.sourceforge.net> | 2005-06-11 16:43:06 +0200 |
---|---|---|
committer | matthiasgrimm <matthiasgrimm@users.sourceforge.net> | 2005-06-11 16:43:06 +0200 |
commit | 869379f57546991e7c0d23b35ddca73b7baca07d (patch) | |
tree | fa340148b32fab0ccc8b34b931dc462dc637d055 | |
parent | 3f7fe29a211a48724e157827ed683555c6f2bb98 (diff) | |
download | rpg-869379f57546991e7c0d23b35ddca73b7baca07d.tar.gz rpg-869379f57546991e7c0d23b35ddca73b7baca07d.tar.bz2 |
aspell error workaround
Aspell breaks its own output format due to undocumented features.
This patch worked around this error. Problems regarding freezing
of the spellchecker or jammed wiki pages through the spellchecker
are solved.
darcs-hash:20050611144306-7ef76-a2df9998b5a888e9fe121acf0c2530c33c2ef2a2.gz
-rw-r--r-- | inc/aspell.php | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/inc/aspell.php b/inc/aspell.php index c0dc429bd..62c3a2ae9 100644 --- a/inc/aspell.php +++ b/inc/aspell.php @@ -145,6 +145,7 @@ class Aspell{ return true; } + /** * Pipes a text to aspell * @@ -178,14 +179,35 @@ class Aspell{ foreach($data as $line){ fwrite($pipes[0],"^$line\n"); // aspell uses ^ to escape the line fflush($pipes[0]); - $line = ''; do{ - $r = fread($pipes[1],1); - $line .= $r; + $r = fgets($pipes[1],8192); + + // Aspell returns lines with preceding '?' like ispell do + // but this lines are badly corrupted. We had to correct + // those lines here due to not to break our result parser. + if($r[0] == '?'){ + $pos = strpos($r, "&"); + if ($pos === false){ + // Is this the last spelling error in the source line, + // then the result line is not terminated with a newline. + // We add one here. The pipe is empty so we prepare + // to leave the loop. + $out .= $r."\n"; + $r = "\n"; // trick to exit the loop + }else{ + // If another word in the source line is misspelled, + // the result line is directly joined to the '?' + // line. We divide them here and add the missing + // newlines. After that we continue to read the pipe. + $out .= str_replace("&", "\n&", $r); + $r = "x"; // trick to loop again for sure + } + }else{ + $out .= $r; + } + if(feof($pipes[1])) break; - if($r == "\n") break; - }while($line != "\n"); - $out .= $line; + }while($r != "\n"); } fclose($pipes[0]); |