hunspell-i18n 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rake'
2
- require 'rake/rdoctask'
2
+ require 'rdoc/task'
3
3
 
4
4
  desc 'Default: create gemspec'
5
5
  task :default => :gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -2,7 +2,6 @@
2
2
  #include <hunspell/hunspell.h>
3
3
 
4
4
  static VALUE rb_cHunspell;
5
- static VALUE rb_cIconv;
6
5
  static VALUE enc_utf8;
7
6
  static VALUE enc_iso8859_1;
8
7
 
@@ -10,6 +9,10 @@ static void dict_destroy(Hunhandle *handle) {
10
9
  Hunspell_destroy(handle);
11
10
  }
12
11
 
12
+ static VALUE hunspell_alloc(VALUE klass) {
13
+ return Data_Wrap_Struct(klass, 0, dict_destroy, 0);
14
+ }
15
+
13
16
  /*
14
17
  * call-seq:
15
18
  * Hunspell.new(affix_path, dic_path)
@@ -20,24 +23,15 @@ static void dict_destroy(Hunhandle *handle) {
20
23
  * speller = Hunspell.new("/usr/share/myspell/en_US.aff", "/usr/share/myspell/en_US.dic")
21
24
  *
22
25
  */
23
- static VALUE dict_init(VALUE self, VALUE affix_path, VALUE dic_path) {
26
+ static VALUE hunspell_initialize(VALUE self, VALUE affix_path, VALUE dic_path) {
24
27
  VALUE affpath = StringValue(affix_path), dpath = StringValue(dic_path);
25
28
  Hunhandle *handle = Hunspell_create(RSTRING_PTR(affpath), RSTRING_PTR(dpath));
26
29
  if (!handle) {
27
30
  rb_raise(rb_eRuntimeError, "Failed to initialize Hunspell handle.");
28
31
  }
29
- VALUE dict = Data_Wrap_Struct(rb_cHunspell, NULL, dict_destroy, handle);
30
- rb_iv_set(self, "dict", dict);
31
- return self;
32
- }
32
+ DATA_PTR(self) = handle;
33
33
 
34
- static inline Hunhandle* get_handle(VALUE self) {
35
- Hunhandle *handle = NULL;
36
- Data_Get_Struct(rb_iv_get(self, "dict"), Hunhandle, handle);
37
- if (!handle) {
38
- rb_raise(rb_eRuntimeError, "Hunspell handle not found.");
39
- }
40
- return handle;
34
+ return self;
41
35
  }
42
36
 
43
37
  /*
@@ -47,7 +41,7 @@ static inline Hunhandle* get_handle(VALUE self) {
47
41
  * Returns the encoding of the dictionary.
48
42
  */
49
43
  static VALUE wrap_encoding(VALUE self) {
50
- Hunhandle *handle = get_handle(self);
44
+ Hunhandle *handle = (Hunhandle *)DATA_PTR(self);
51
45
  char *enc = Hunspell_get_dic_encoding(handle);
52
46
  return rb_str_new2(enc);
53
47
  }
@@ -64,8 +58,7 @@ static VALUE recode_if_needed(VALUE self, VALUE str, int dir) {
64
58
  to = enc_utf8;
65
59
  }
66
60
  if ( rb_str_equal(enc, enc_iso8859_1) == Qfalse && rb_str_equal(enc, enc_utf8) == Qfalse) {
67
- rb_funcall(str, rb_intern("force_encoding"), 1, enc_utf8);
68
- return rb_funcall(rb_cIconv, rb_intern("conv"), 3, to, from, str);
61
+ return rb_funcall(str, rb_intern("encode"), 2, to, from);
69
62
  } else {
70
63
  return str;
71
64
  }
@@ -82,7 +75,7 @@ static VALUE wrap_suggest(VALUE self, VALUE word) {
82
75
  VALUE res;
83
76
  char** slst = NULL;
84
77
  int i, count = 0;
85
- Hunhandle *handle = get_handle(self);
78
+ Hunhandle *handle = (Hunhandle *)DATA_PTR(self);
86
79
 
87
80
  count = Hunspell_suggest(handle, &slst, RSTRING_PTR(str));
88
81
 
@@ -107,7 +100,7 @@ static VALUE wrap_suggest(VALUE self, VALUE word) {
107
100
  */
108
101
  static VALUE wrap_check(VALUE self, VALUE word) {
109
102
  VALUE str = recode_if_needed(self, StringValue(word), 0);
110
- Hunhandle *handle = get_handle(self);
103
+ Hunhandle *handle = (Hunhandle *)DATA_PTR(self);
111
104
  int rc = Hunspell_spell(handle, RSTRING_PTR(str));
112
105
  return rc == 0 ? Qfalse : Qtrue;
113
106
  }
@@ -115,13 +108,12 @@ static VALUE wrap_check(VALUE self, VALUE word) {
115
108
 
116
109
  void Init_hunspell(void) {
117
110
  rb_cHunspell = rb_define_class("Hunspell", rb_cObject);
118
- rb_define_method(rb_cHunspell, "initialize", dict_init, 2);
111
+ rb_define_alloc_func(rb_cHunspell, hunspell_alloc);
112
+ rb_define_method(rb_cHunspell, "initialize", hunspell_initialize, 2);
119
113
  //rb_define_method(rb_cHunspell, "check?", wrap_check, 1);
120
114
  rb_define_method(rb_cHunspell, "valid?", wrap_check, 1);
121
115
  rb_define_method(rb_cHunspell, "suggest", wrap_suggest, 1);
122
116
  rb_define_method(rb_cHunspell, "encoding", wrap_encoding, 0);
123
- rb_require("iconv");
124
- rb_cIconv = rb_const_get(rb_cObject, rb_intern("Iconv"));
125
117
  enc_iso8859_1 = rb_str_new2("ISO8859-1");
126
118
  enc_utf8 = rb_str_new2("UTF-8");
127
119
  rb_global_variable(&enc_iso8859_1);
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hunspell-i18n"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Shterenzon"]
12
- s.date = "2012-02-10"
12
+ s.date = "2012-08-15"
13
13
  s.description = "Ruby bindings for libhunspell-1.2 with i18n support"
14
14
  s.email = "romanbsd@yahoo.com"
15
15
  s.extensions = ["ext/extconf.rb"]
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  ]
30
30
  s.homepage = "http://github.com/romanbsd/hunspell"
31
31
  s.require_paths = ["lib"]
32
- s.rubygems_version = "1.8.15"
32
+ s.rubygems_version = "1.8.24"
33
33
  s.summary = "Ruby bindings for libhunspell-1.2 with i18n support"
34
34
 
35
35
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,27 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hunspell-i18n
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
4
5
  prerelease:
5
- version: 0.2.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Roman Shterenzon
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-02-10 00:00:00 Z
12
+ date: 2012-08-15 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
14
  description: Ruby bindings for libhunspell-1.2 with i18n support
17
15
  email: romanbsd@yahoo.com
18
16
  executables: []
19
-
20
- extensions:
17
+ extensions:
21
18
  - ext/extconf.rb
22
- extra_rdoc_files:
19
+ extra_rdoc_files:
23
20
  - README.md
24
- files:
21
+ files:
25
22
  - .rspec
26
23
  - README.md
27
24
  - Rakefile
@@ -33,30 +30,26 @@ files:
33
30
  - spec/spec_helper.rb
34
31
  homepage: http://github.com/romanbsd/hunspell
35
32
  licenses: []
36
-
37
33
  post_install_message:
38
34
  rdoc_options: []
39
-
40
- require_paths:
35
+ require_paths:
41
36
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
37
+ required_ruby_version: !ruby/object:Gem::Requirement
43
38
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
- required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
44
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
54
49
  requirements: []
55
-
56
50
  rubyforge_project:
57
- rubygems_version: 1.8.15
51
+ rubygems_version: 1.8.24
58
52
  signing_key:
59
53
  specification_version: 3
60
54
  summary: Ruby bindings for libhunspell-1.2 with i18n support
61
55
  test_files: []
62
-