iconv 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,15 +1,19 @@
1
1
  *.gem
2
+ *.o
2
3
  *.rbc
4
+ *.so
3
5
  *.swp
4
6
  .bundle
5
7
  .config
6
8
  .yardoc
7
9
  Gemfile.lock
8
10
  InstalledFiles
11
+ Makefile
9
12
  _yardoc
10
13
  coverage
11
14
  doc/
12
15
  lib/bundler/man
16
+ mkmf.log
13
17
  pkg
14
18
  rdoc
15
19
  spec/reports
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - 1.8.7
7
+
8
+ branches:
9
+ only:
10
+ - master
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in iconv.gemspec
4
4
  gemspec
5
+ gem "rake"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Iconv
2
2
 
3
+ [![Build Status](https://travis-ci.org/nurse/iconv.png)](https://travis-ci.org/nurse/iconv)
4
+
3
5
  iconv wrapper, used to be ext/iconv
4
6
 
5
7
  ## Abstract
data/Rakefile CHANGED
@@ -12,8 +12,8 @@ file "lib/#{NAME}/#{NAME}.so" =>
12
12
  Dir.chdir("ext/#{NAME}") do
13
13
  # this does essentially the same thing
14
14
  # as what RubyGems does
15
- ruby "extconf.rb"
16
- sh "make"
15
+ ruby "extconf.rb", *ARGV.grep(/\A--/)
16
+ sh "make", *ARGV.grep(/\A(?!--)/)
17
17
  end
18
18
  cp "ext/#{NAME}/#{NAME}.so", "lib/#{NAME}"
19
19
  end
@@ -5,8 +5,9 @@ dir_config("iconv")
5
5
  conf = File.exist?(File.join($srcdir, "config.charset"))
6
6
  conf = with_config("config-charset", enable_config("config-charset", conf))
7
7
 
8
- have_func("rb_enc_get", "ruby/encoding.h")
9
- have_func("st_lookup", "ruby/st.h")
8
+ unless have_func("rb_enc_get", "ruby/encoding.h") || have_func("vasprintf", "stdio.h")
9
+ raise "vasprintf is required for Ruby 1.8"
10
+ end
10
11
  if have_func("iconv", "iconv.h") or
11
12
  have_library("iconv", "iconv", "iconv.h")
12
13
  check_signedness("size_t") rescue nil
@@ -17,13 +17,60 @@
17
17
  #include <errno.h>
18
18
  #include <iconv.h>
19
19
  #include <assert.h>
20
- #ifdef HAVE_RUBY_ST_H
21
- #include "ruby/st.h"
22
- #else /* assume 1.8 */
23
- #include "st.h"
24
- #endif
25
20
  #ifdef HAVE_RUBY_ENCODING_H
26
- #include "ruby/encoding.h"
21
+ /* assume Ruby 1.9 or later */
22
+ # include "ruby/st.h"
23
+ # include "ruby/encoding.h"
24
+ #else
25
+ # include "st.h"
26
+ # include <stdarg.h>
27
+ # define rb_f_notimplement rb_notimplement
28
+ # define rb_str_subseq(a, b, c) rb_str_substr(a, b, c)
29
+ # define rb_str_new_cstr(a) rb_str_new2(a)
30
+ NORETURN(static void rb_sys_fail_str(VALUE msg));
31
+ static void
32
+ rb_sys_fail_str(VALUE msg)
33
+ {
34
+ rb_sys_fail(RSTRING_PTR(msg));
35
+ }
36
+ static VALUE
37
+ rb_str_equal(str1, str2)
38
+ VALUE str1, str2;
39
+ {
40
+ if (str1 == str2) return Qtrue;
41
+ if (TYPE(str2) != T_STRING) {
42
+ if (!rb_respond_to(str2, rb_intern("to_str"))) {
43
+ return Qfalse;
44
+ }
45
+ return rb_equal(str2, str1);
46
+ }
47
+ if (RSTRING(str1)->len == RSTRING(str2)->len &&
48
+ rb_str_cmp(str1, str2) == 0) {
49
+ return Qtrue;
50
+ }
51
+ return Qfalse;
52
+ }
53
+ void
54
+ rb_set_errinfo(VALUE err)
55
+ {
56
+ extern VALUE ruby_errinfo;
57
+ ruby_errinfo = err;
58
+ }
59
+ #define ENCODING_GET(a) 0
60
+ VALUE
61
+ rb_sprintf(const char *format, ...)
62
+ {
63
+ va_list ap;
64
+ char *ret;
65
+ int len;
66
+
67
+ va_start(ap, format);
68
+ len = vasprintf(&ret, format, ap);
69
+ va_end(ap);
70
+ if (len == -1) return Qnil;
71
+
72
+ return rb_str_new(ret, len);
73
+ }
27
74
  #endif
28
75
 
29
76
  /*
@@ -212,7 +259,9 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt, int *idx)
212
259
  iconv_t cd;
213
260
  int retry = 0;
214
261
 
262
+ #ifdef HAVE_RUBY_ENCODING_H
215
263
  *idx = rb_enc_find_index(tocode);
264
+ #endif
216
265
 
217
266
  if (toopt) {
218
267
  toenc = rb_str_plus(to, toopt);
@@ -499,7 +548,9 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
499
548
  {
500
549
  if (NIL_P(str)) {
501
550
  ret = rb_str_new(buffer, outlen);
551
+ #ifdef HAVE_RUBY_ENCODING_H
502
552
  if (toidx >= 0) rb_enc_associate_index(ret, toidx);
553
+ #endif
503
554
  }
504
555
  else {
505
556
  if (ret) {
@@ -507,7 +558,9 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
507
558
  }
508
559
  else {
509
560
  ret = rb_str_new(instart, tmpstart - instart);
561
+ #ifdef HAVE_RUBY_ENCODING_H
510
562
  if (toidx >= 0) rb_enc_associate_index(ret, toidx);
563
+ #endif
511
564
  OBJ_INFECT(ret, str);
512
565
  }
513
566
  ret = rb_str_buf_cat(ret, buffer, outlen);
@@ -529,7 +582,9 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
529
582
 
530
583
  if (!ret) {
531
584
  ret = rb_str_derive(str, instart, inptr - instart);
585
+ #ifdef HAVE_RUBY_ENCODING_H
532
586
  if (toidx >= 0) rb_enc_associate_index(ret, toidx);
587
+ #endif
533
588
  }
534
589
  else if (inptr > instart) {
535
590
  rb_str_cat(ret, instart, inptr - instart);
@@ -555,7 +610,9 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
555
610
 
556
611
  if (!ret) {
557
612
  ret = rb_str_derive(str, instart, inptr - instart);
613
+ #ifdef HAVE_RUBY_ENCODING_H
558
614
  if (toidx >= 0) rb_enc_associate_index(ret, toidx);
615
+ #endif
559
616
  }
560
617
  else if (inptr > instart) {
561
618
  rb_str_cat(ret, instart, inptr - instart);
@@ -673,7 +730,9 @@ iconv_initialize(int argc, VALUE *argv, VALUE self)
673
730
  iconv_free(check_iconv(self));
674
731
  DATA_PTR(self) = NULL;
675
732
  DATA_PTR(self) = (void *)ICONV2VALUE(iconv_create(to, from, &opt, &idx));
733
+ #ifdef HAVE_RUBY_ENCODING_H
676
734
  if (idx >= 0) ENCODING_SET(self, idx);
735
+ #endif
677
736
  return self;
678
737
  }
679
738
 
@@ -697,7 +756,9 @@ iconv_s_open(int argc, VALUE *argv, VALUE self)
697
756
  cd = ICONV2VALUE(iconv_create(to, from, &opt, &idx));
698
757
 
699
758
  self = Data_Wrap_Struct(self, NULL, ICONV_FREE, (void *)cd);
759
+ #ifdef HAVE_RUBY_ENCODING_H
700
760
  if (idx >= 0) ENCODING_SET(self, idx);
761
+ #endif
701
762
 
702
763
  if (rb_block_given_p()) {
703
764
  return rb_ensure(rb_yield, self, (VALUE(*)())iconv_finish, self);
@@ -838,7 +899,7 @@ iconv_s_list(void)
838
899
 
839
900
  args[1] = rb_block_given_p() ? 0 : rb_ary_new();
840
901
  iconvlist(list_iconv, args);
841
- state = *(int *)args;
902
+ state = (int)args[0];
842
903
  if (state) rb_jump_tag(state);
843
904
  if (args[1]) return args[1];
844
905
  #elif defined(HAVE___ICONV_FREE_LIST)
@@ -930,27 +991,38 @@ iconv_iconv(int argc, VALUE *argv, VALUE self)
930
991
 
931
992
  rb_scan_args(argc, argv, "12", &str, &n1, &n2);
932
993
  if (!NIL_P(str)) {
994
+ #ifdef HAVE_RUBY_ENCODING_H
933
995
  VALUE n = rb_str_length(StringValue(str));
934
996
  slen = NUM2LONG(n);
997
+ #else
998
+ slen = RSTRING_LEN(StringValue(str));
999
+ #endif
935
1000
  }
936
1001
  if (argc != 2 || !RTEST(rb_range_beg_len(n1, &start, &length, slen, 0))) {
937
1002
  if (NIL_P(n1) || ((start = NUM2LONG(n1)) < 0 ? (start += slen) >= 0 : start < slen)) {
938
1003
  length = NIL_P(n2) ? -1 : NUM2LONG(n2);
939
1004
  }
940
1005
  }
941
- #ifdef HAVE_RUBY_ENCODING_H
942
1006
  if (start > 0 || length > 0) {
943
- rb_encoding *enc = rb_enc_get(str);
1007
+ #ifdef HAVE_RUBY_ENCODING_H
944
1008
  const char *s = RSTRING_PTR(str), *e = s + RSTRING_LEN(str);
945
1009
  const char *ps = s;
1010
+ rb_encoding *enc = rb_enc_get(str);
946
1011
  if (start > 0) {
947
1012
  start = (ps = rb_enc_nth(s, e, start, enc)) - s;
948
1013
  }
949
1014
  if (length > 0) {
950
1015
  length = rb_enc_nth(ps, e, length, enc) - ps;
951
1016
  }
952
- }
1017
+ #else
1018
+ if (start > slen) {
1019
+ start = slen;
1020
+ }
1021
+ if (length > slen - start) {
1022
+ length = slen - start;
1023
+ }
953
1024
  #endif
1025
+ }
954
1026
 
955
1027
  return iconv_convert(VALUE2ICONV(cd), str, start, length, ENCODING_GET(self), NULL);
956
1028
  }
@@ -8,7 +8,7 @@ require 'optparse'
8
8
  HEADER = <<SRC
9
9
  require 'iconv.so'
10
10
 
11
- class Iconv
11
+ class Iconv < Data
12
12
  case RUBY_PLATFORM
13
13
  SRC
14
14
 
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
+ gem.required_ruby_version = '>= 1.9.2'
20
21
  end
@@ -1,6 +1,6 @@
1
1
  require "iconv/iconv.so"
2
2
  require "iconv/version"
3
3
 
4
- class Iconv
4
+ class Iconv < Data
5
5
  # Your code goes here...
6
6
  end
@@ -1,3 +1,3 @@
1
- class Iconv
2
- VERSION = "1.0.1"
1
+ class Iconv < Data
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,4 +1,4 @@
1
- require_relative "utils.rb"
1
+ require File.expand_path("../utils.rb", __FILE__)
2
2
 
3
3
  class TestIconv::Basic < TestIconv
4
4
  def test_euc2sjis
@@ -1,4 +1,4 @@
1
- require_relative "utils.rb"
1
+ require File.expand_path("../utils.rb", __FILE__)
2
2
 
3
3
  class TestIconv::Option < TestIconv
4
4
  def test_ignore_option
@@ -1,4 +1,4 @@
1
- require_relative "utils.rb"
1
+ require File.expand_path("../utils.rb", __FILE__)
2
2
 
3
3
  class TestIconv::Partial < TestIconv
4
4
  def test_partial_ascii
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: iconv wrapper library
15
15
  email:
@@ -20,6 +20,7 @@ extensions:
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
+ - .travis.yml
23
24
  - BSDL
24
25
  - Gemfile
25
26
  - LICENSE.txt
@@ -47,13 +48,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
48
  requirements:
48
49
  - - ! '>='
49
50
  - !ruby/object:Gem::Version
50
- version: '0'
51
+ version: 1.9.2
51
52
  required_rubygems_version: !ruby/object:Gem::Requirement
52
53
  none: false
53
54
  requirements:
54
55
  - - ! '>='
55
56
  - !ruby/object:Gem::Version
56
57
  version: '0'
58
+ segments:
59
+ - 0
60
+ hash: -4204543701599333297
57
61
  requirements: []
58
62
  rubyforge_project:
59
63
  rubygems_version: 1.8.24
@@ -65,4 +69,3 @@ test_files:
65
69
  - test/test_option.rb
66
70
  - test/test_partial.rb
67
71
  - test/utils.rb
68
- has_rdoc: