Skip to content

Commit

Permalink
Aspell lib expects the bytesize of the word
Browse files Browse the repository at this point in the history
Fixes bug with strings containing multibyte
characters (for example, all languages using non ascii part
of UTF-8).

Ref: http://aspell.net/0.50-doc/man-html/6_Writing.html

Signed-off-by: Potamianos Gregory <gregory@skroutz.gr>
Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
  • Loading branch information
gregoryp authored and Yorick Peterse committed Jul 6, 2012
1 parent 6cc0aae commit 25dfddc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ffi/aspell/speller.rb
Expand Up @@ -118,7 +118,7 @@ def correct?(word)
end

speller = Aspell.speller_new(@config)
correct = Aspell.speller_check(speller, word.to_s, word.length)
correct = Aspell.speller_check(speller, word.to_s, word.bytesize)

Aspell.speller_delete(speller)

Expand All @@ -139,7 +139,7 @@ def suggestions(word)
end

speller = Aspell.speller_new(@config)
list = Aspell.speller_suggest(speller, word, word.length)
list = Aspell.speller_suggest(speller, word, word.bytesize)
suggestions = []
elements = Aspell.word_list_elements(list)

Expand Down
9 changes: 9 additions & 0 deletions spec/ffi/aspell/speller.rb
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

require File.expand_path('../../../helper', __FILE__)

describe 'FFI::Aspell::Speller' do
Expand Down Expand Up @@ -60,6 +62,13 @@
speller.correct?('huis').should == true
end

it 'Validate some UTF-8 (Greek) words' do
speller = FFI::Aspell::Speller.new('el')

speller.correct?('χταπόδι').should == true
speller.correct?('οιρανός').should == false
end

it 'Change the language of an existing speller object' do
speller = FFI::Aspell::Speller.new

Expand Down

0 comments on commit 25dfddc

Please sign in to comment.