ruby-bsdconv 11.1.0 → 11.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/Rakefile +12 -20
- data/doc/api.rst +99 -0
- data/example/{example.rb → example_chunk.rb} +0 -0
- data/example/example_conv.rb +18 -0
- data/example/example_conv_file.rb +14 -0
- data/example/{example3.rb → example_ctl.rb} +1 -1
- data/example/example_insert_replace.rb +19 -0
- data/example/example_modules.rb +14 -0
- data/ext/ruby-bsdconv/bsdconv.c +19 -19
- data/ruby-bsdconv.gemspec +14 -9
- data/task/gemgem.rb +145 -68
- data/test/test_basic.rb +4 -4
- metadata +14 -10
- data/README +0 -3
- data/example/example2.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac83b010e742d45610e126dbf4e0fec6fcd3b717
|
4
|
+
data.tar.gz: ec794f163b76f01e5bdd6a9fd481affeeab81215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efa3bf01b8e64282a142dad8315df7a9db9254335dce0b6cced96e285b7317200dbba88bc1d84153f89cf5c1f12e7812097664f4289e049f46e02aef00507a9d
|
7
|
+
data.tar.gz: 9e83c49f520b3c95dd5700ae0383776f6269cca868e36025149ad1863a98193d1cd296abfa0aebeeb7d0183d7fb31ea5b4e9c56583f6bab2800f8d1bb346cecf
|
data/README.md
ADDED
data/Rakefile
CHANGED
@@ -2,24 +2,16 @@
|
|
2
2
|
|
3
3
|
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
4
4
|
|
5
|
-
Gemgem.dir
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
17
|
-
s.license = 'BSD'
|
18
|
-
s.summary = 'ruby wrapper for bsdconv'
|
19
|
-
s.description =
|
20
|
-
"#{s.summary}. bsdconv is a BSD licensed charset/encoding converter" \
|
21
|
-
" library with more functionalities than libiconv"
|
22
|
-
end
|
23
|
-
|
24
|
-
Gemgem.write
|
5
|
+
Gemgem.init(dir) do |s|
|
6
|
+
s.name = 'ruby-bsdconv'
|
7
|
+
s.version = '11.3.1'
|
8
|
+
s.extensions = 'ext/ruby-bsdconv/extconf.rb'
|
9
|
+
s.authors = ['Buganini Q']
|
10
|
+
s.email = 'buganini@gmail.com'
|
11
|
+
s.homepage = 'https://github.com/buganini/ruby-bsdconv'
|
12
|
+
s.license = 'BSD'
|
13
|
+
s.summary = 'ruby wrapper for bsdconv'
|
14
|
+
s.description =
|
15
|
+
"#{s.summary}. bsdconv is a BSD licensed charset/encoding converter" \
|
16
|
+
" library with more functionalities than libiconv"
|
25
17
|
end
|
data/doc/api.rst
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
Ruby binding API
|
2
|
+
================
|
3
|
+
|
4
|
+
.. rb:module:: bsdconv
|
5
|
+
|
6
|
+
.. rb:class:: Bsdconv
|
7
|
+
|
8
|
+
.. rb:const:: FILTER
|
9
|
+
.. rb:const:: FROM
|
10
|
+
.. rb:const:: INTER
|
11
|
+
.. rb:const:: TO
|
12
|
+
|
13
|
+
Phase type
|
14
|
+
|
15
|
+
.. rb:const:: CTL_ATTACH_SCORE
|
16
|
+
.. rb:const:: CTL_ATTACH_OUTPUT_FILE
|
17
|
+
.. rb:const:: CTL_AMBIGUOUS_PAD
|
18
|
+
|
19
|
+
Request for :rb:meth:`ctl`
|
20
|
+
|
21
|
+
.. rb:classmethod:: new(conversion)
|
22
|
+
|
23
|
+
Create converter instance with given conversion string
|
24
|
+
|
25
|
+
.. rb:classmethod:: insert_phase(conversion, codec, phase_type, phasen)
|
26
|
+
|
27
|
+
Insert conversion phase into bsdconv conversion string
|
28
|
+
|
29
|
+
.. rb:classmethod:: insert_codec(conversion, codec, phasen, codecn)
|
30
|
+
|
31
|
+
Insert conversion codec into bsdconv conversion string
|
32
|
+
|
33
|
+
.. rb:classmethod:: replace_phase(conversion, codec, phase_type, phasen)
|
34
|
+
|
35
|
+
Replace conversion phase in the bsdconv conversion string
|
36
|
+
|
37
|
+
.. rb:classmethod:: replace_codec(conversion, codec, phasen, codecn)
|
38
|
+
|
39
|
+
Replace conversion codec in the bsdconv conversion string
|
40
|
+
|
41
|
+
.. rb:classmethod:: error()
|
42
|
+
|
43
|
+
Get error message
|
44
|
+
|
45
|
+
.. rb:classmethod:: codecs_list(type)
|
46
|
+
|
47
|
+
DEPRECATED: Use :rb:meth:`modules_list` instead
|
48
|
+
|
49
|
+
.. rb:classmethod:: modules_list(type)
|
50
|
+
|
51
|
+
Get modules list of specified type
|
52
|
+
|
53
|
+
.. rb:classmethod:: codec_check(type, module)
|
54
|
+
|
55
|
+
DEPRECATED: Use :rb:meth:`module_check` instead
|
56
|
+
|
57
|
+
.. rb:classmethod:: module_check(type, module)
|
58
|
+
|
59
|
+
Check availability with given type and module name
|
60
|
+
|
61
|
+
.. rb:classmethod:: mktemp(template)
|
62
|
+
|
63
|
+
mkstemp()
|
64
|
+
|
65
|
+
.. rb:classmethod:: fopen(path, mode)
|
66
|
+
|
67
|
+
fopen()
|
68
|
+
|
69
|
+
.. rb:method:: conv(s)
|
70
|
+
|
71
|
+
Perform conversion
|
72
|
+
|
73
|
+
.. rb:method:: init()
|
74
|
+
|
75
|
+
Initialize/Reset bsdconv converter
|
76
|
+
|
77
|
+
.. rb:method:: ctl(arg_ptr_obj, arg_int)
|
78
|
+
|
79
|
+
Manipulate the underlying codec parameters
|
80
|
+
|
81
|
+
.. rb:method:: conv_chunk(s)
|
82
|
+
|
83
|
+
Perform conversion without initializing and flushing
|
84
|
+
|
85
|
+
.. rb:method:: conv_chunk_last(s)
|
86
|
+
|
87
|
+
Perform conversion without initializing
|
88
|
+
|
89
|
+
.. rb:method:: conv_file(from_file, to_file)
|
90
|
+
|
91
|
+
Perform conversion with given filename
|
92
|
+
|
93
|
+
.. rb:method:: counter([name])
|
94
|
+
|
95
|
+
Return conversion info
|
96
|
+
|
97
|
+
.. rb:method:: counter_reset([name])
|
98
|
+
|
99
|
+
Reset counter, if no name supplied, all counters will be reset
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bsdconv'
|
4
|
+
|
5
|
+
sin="utf-8:utf-8,ascii"
|
6
|
+
sout=Bsdconv.insert_phase(sin, "upper", Bsdconv::INTER, 1)
|
7
|
+
puts sout
|
8
|
+
|
9
|
+
sin=sout
|
10
|
+
sout=Bsdconv.replace_phase(sin, "full", Bsdconv::INTER, 1)
|
11
|
+
puts sout
|
12
|
+
|
13
|
+
sin=sout
|
14
|
+
sout=Bsdconv.replace_codec(sin, "big5", 2, 1)
|
15
|
+
puts sout
|
16
|
+
|
17
|
+
sin=sout
|
18
|
+
sout=Bsdconv.insert_codec(sin, "ascii", 0, 1)
|
19
|
+
puts sout
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bsdconv'
|
4
|
+
|
5
|
+
p Bsdconv.module_check(Bsdconv::FROM, "_utf-8")
|
6
|
+
p Bsdconv.module_check(Bsdconv::INTER, "_utf-8")
|
7
|
+
puts 'Filter:'
|
8
|
+
p Bsdconv.modules_list(Bsdconv::FILTER)
|
9
|
+
puts 'From:'
|
10
|
+
p Bsdconv.modules_list(Bsdconv::FROM)
|
11
|
+
puts 'Inter:'
|
12
|
+
p Bsdconv.modules_list(Bsdconv::INTER)
|
13
|
+
puts 'To:'
|
14
|
+
p Bsdconv.modules_list(Bsdconv::TO)
|
data/ext/ruby-bsdconv/bsdconv.c
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2011-
|
2
|
+
* Copyright (c) 2011-2014 Kuan-Chung Chiu <buganini@gmail.com>
|
3
3
|
*
|
4
4
|
* Permission to use, copy, modify, and distribute this software for any
|
5
5
|
* purpose with or without fee is hereby granted, provided that the above
|
@@ -40,7 +40,6 @@ static VALUE m_conv_chunk_last(VALUE, VALUE);
|
|
40
40
|
static VALUE m_conv_file(VALUE, VALUE, VALUE);
|
41
41
|
static VALUE m_counter(int, VALUE *, VALUE);
|
42
42
|
static VALUE m_counter_reset(int, VALUE *, VALUE);
|
43
|
-
static VALUE m_nil(VALUE);
|
44
43
|
static VALUE m_inspect(VALUE);
|
45
44
|
|
46
45
|
static VALUE f_insert_phase(VALUE, VALUE, VALUE, VALUE, VALUE);
|
@@ -48,8 +47,8 @@ static VALUE f_insert_codec(VALUE, VALUE, VALUE, VALUE, VALUE);
|
|
48
47
|
static VALUE f_replace_phase(VALUE, VALUE, VALUE, VALUE, VALUE);
|
49
48
|
static VALUE f_replace_codec(VALUE, VALUE, VALUE, VALUE, VALUE);
|
50
49
|
static VALUE f_error(VALUE);
|
51
|
-
static VALUE
|
52
|
-
static VALUE
|
50
|
+
static VALUE f_modules_list(VALUE, VALUE);
|
51
|
+
static VALUE f_module_check(VALUE, VALUE, VALUE);
|
53
52
|
static VALUE f_mktemp(VALUE, VALUE);
|
54
53
|
static VALUE f_fopen(VALUE, VALUE, VALUE);
|
55
54
|
|
@@ -68,22 +67,24 @@ void Init_bsdconv(){
|
|
68
67
|
rb_define_method(Bsdconv, "counter_reset", m_counter_reset, -1);
|
69
68
|
rb_define_method(Bsdconv, "inspect", m_inspect, 0);
|
70
69
|
|
70
|
+
rb_define_const(Bsdconv, "FILTER", INT2NUM(FILTER));
|
71
71
|
rb_define_const(Bsdconv, "FROM", INT2NUM(FROM));
|
72
72
|
rb_define_const(Bsdconv, "INTER", INT2NUM(INTER));
|
73
73
|
rb_define_const(Bsdconv, "TO", INT2NUM(TO));
|
74
74
|
|
75
|
-
rb_define_const(Bsdconv, "CTL_ATTACH_SCORE", INT2NUM(
|
76
|
-
rb_define_const(Bsdconv, "
|
77
|
-
rb_define_const(Bsdconv, "
|
78
|
-
rb_define_const(Bsdconv, "CTL_ATTACH_OUTPUT_FILE", INT2NUM(BSDCONV_ATTACH_OUTPUT_FILE));
|
75
|
+
rb_define_const(Bsdconv, "CTL_ATTACH_SCORE", INT2NUM(BSDCONV_CTL_ATTACH_SCORE));
|
76
|
+
rb_define_const(Bsdconv, "CTL_ATTACH_OUTPUT_FILE", INT2NUM(BSDCONV_CTL_ATTACH_OUTPUT_FILE));
|
77
|
+
rb_define_const(Bsdconv, "CTL_AMBIGUOUS_PAD", INT2NUM(BSDCONV_CTL_AMBIGUOUS_PAD));
|
79
78
|
|
80
79
|
rb_define_singleton_method(Bsdconv, "insert_phase", f_insert_phase, 4);
|
81
80
|
rb_define_singleton_method(Bsdconv, "insert_codec", f_insert_codec, 4);
|
82
81
|
rb_define_singleton_method(Bsdconv, "replace_phase", f_replace_phase, 4);
|
83
82
|
rb_define_singleton_method(Bsdconv, "replace_codec", f_replace_codec, 4);
|
84
83
|
rb_define_singleton_method(Bsdconv, "error", f_error, 0);
|
85
|
-
rb_define_singleton_method(Bsdconv, "
|
86
|
-
rb_define_singleton_method(Bsdconv, "
|
84
|
+
rb_define_singleton_method(Bsdconv, "modules_list", f_modules_list, 1);
|
85
|
+
rb_define_singleton_method(Bsdconv, "module_check", f_module_check, 2);
|
86
|
+
rb_define_singleton_method(Bsdconv, "codecs_list", f_modules_list, 1);
|
87
|
+
rb_define_singleton_method(Bsdconv, "codec_check", f_module_check, 2);
|
87
88
|
rb_define_singleton_method(Bsdconv, "mktemp", f_mktemp, 1);
|
88
89
|
rb_define_singleton_method(Bsdconv, "fopen", f_fopen, 2);
|
89
90
|
|
@@ -246,7 +247,6 @@ static VALUE m_counter(int argc, VALUE *argv, VALUE self){
|
|
246
247
|
}
|
247
248
|
|
248
249
|
static VALUE m_counter_reset(int argc, VALUE *argv, VALUE self){
|
249
|
-
VALUE ret;
|
250
250
|
struct bsdconv_instance *ins;
|
251
251
|
Data_Get_Struct(self, struct bsdconv_instance, ins);
|
252
252
|
if(argc!=0){
|
@@ -277,28 +277,28 @@ static VALUE m_inspect(VALUE self){
|
|
277
277
|
|
278
278
|
static VALUE f_insert_phase(VALUE self, VALUE conversion, VALUE codec, VALUE phase_type, VALUE phasen){
|
279
279
|
char *s=bsdconv_insert_phase(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phase_type), NUM2INT(phasen));
|
280
|
-
|
280
|
+
VALUE ret=rb_str_new2(s);
|
281
281
|
bsdconv_free(s);
|
282
282
|
return ret;
|
283
283
|
}
|
284
284
|
|
285
285
|
static VALUE f_insert_codec(VALUE self, VALUE conversion, VALUE codec, VALUE phasen, VALUE codecn){
|
286
286
|
char *s=bsdconv_insert_codec(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phasen), NUM2INT(codecn));
|
287
|
-
|
287
|
+
VALUE ret=rb_str_new2(s);
|
288
288
|
bsdconv_free(s);
|
289
289
|
return ret;
|
290
290
|
}
|
291
291
|
|
292
292
|
static VALUE f_replace_phase(VALUE self, VALUE conversion, VALUE codec, VALUE phase_type, VALUE phasen){
|
293
293
|
char *s=bsdconv_replace_phase(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phase_type), NUM2INT(phasen));
|
294
|
-
|
294
|
+
VALUE ret=rb_str_new2(s);
|
295
295
|
bsdconv_free(s);
|
296
296
|
return ret;
|
297
297
|
}
|
298
298
|
|
299
299
|
static VALUE f_replace_codec(VALUE self, VALUE conversion, VALUE codec, VALUE phasen, VALUE codecn){
|
300
300
|
char *s=bsdconv_replace_codec(RSTRING_PTR(conversion), RSTRING_PTR(codec), NUM2INT(phasen), NUM2INT(codecn));
|
301
|
-
|
301
|
+
VALUE ret=rb_str_new2(s);
|
302
302
|
bsdconv_free(s);
|
303
303
|
return ret;
|
304
304
|
}
|
@@ -311,11 +311,11 @@ static VALUE f_error(VALUE self){
|
|
311
311
|
return ret;
|
312
312
|
}
|
313
313
|
|
314
|
-
static VALUE
|
314
|
+
static VALUE f_modules_list(VALUE self, VALUE phase_type){
|
315
315
|
char **list, **p;
|
316
316
|
VALUE ret;
|
317
317
|
ret=rb_ary_new();
|
318
|
-
list=
|
318
|
+
list=bsdconv_modules_list(NUM2INT(phase_type));
|
319
319
|
p=list;
|
320
320
|
while(*p!=NULL){
|
321
321
|
rb_ary_push(ret, rb_str_new2(*p));
|
@@ -326,8 +326,8 @@ static VALUE f_codecs_list(VALUE self, VALUE phase_type){
|
|
326
326
|
return ret;
|
327
327
|
}
|
328
328
|
|
329
|
-
static VALUE
|
330
|
-
if(
|
329
|
+
static VALUE f_module_check(VALUE self, VALUE phase_type, VALUE codec){
|
330
|
+
if(bsdconv_module_check(NUM2INT(phase_type), RSTRING_PTR(codec))){
|
331
331
|
return Qtrue;
|
332
332
|
}
|
333
333
|
return Qfalse;
|
data/ruby-bsdconv.gemspec
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: ruby-bsdconv 11.1
|
2
|
+
# stub: ruby-bsdconv 11.3.1 ruby lib
|
3
|
+
# stub: ext/ruby-bsdconv/extconf.rb
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
6
|
s.name = "ruby-bsdconv"
|
6
|
-
s.version = "11.1
|
7
|
+
s.version = "11.3.1"
|
7
8
|
|
8
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.require_paths = ["lib"]
|
9
11
|
s.authors = ["Buganini Q"]
|
10
|
-
s.date = "
|
12
|
+
s.date = "2014-05-13"
|
11
13
|
s.description = "ruby wrapper for bsdconv. bsdconv is a BSD licensed charset/encoding converter library with more functionalities than libiconv"
|
12
14
|
s.email = "buganini@gmail.com"
|
13
15
|
s.extensions = ["ext/ruby-bsdconv/extconf.rb"]
|
14
16
|
s.files = [
|
15
17
|
".gitignore",
|
16
|
-
"README",
|
18
|
+
"README.md",
|
17
19
|
"Rakefile",
|
18
|
-
"
|
19
|
-
"example/
|
20
|
-
"example/
|
20
|
+
"doc/api.rst",
|
21
|
+
"example/example_chunk.rb",
|
22
|
+
"example/example_conv.rb",
|
23
|
+
"example/example_conv_file.rb",
|
24
|
+
"example/example_ctl.rb",
|
25
|
+
"example/example_insert_replace.rb",
|
26
|
+
"example/example_modules.rb",
|
21
27
|
"ext/ruby-bsdconv/bsdconv.c",
|
22
28
|
"ext/ruby-bsdconv/extconf.rb",
|
23
29
|
"ruby-bsdconv.gemspec",
|
@@ -25,8 +31,7 @@ Gem::Specification.new do |s|
|
|
25
31
|
"test/test_basic.rb"]
|
26
32
|
s.homepage = "https://github.com/buganini/ruby-bsdconv"
|
27
33
|
s.licenses = ["BSD"]
|
28
|
-
s.
|
29
|
-
s.rubygems_version = "2.1.3"
|
34
|
+
s.rubygems_version = "2.2.2"
|
30
35
|
s.summary = "ruby wrapper for bsdconv"
|
31
36
|
s.test_files = ["test/test_basic.rb"]
|
32
37
|
end
|
data/task/gemgem.rb
CHANGED
@@ -1,106 +1,144 @@
|
|
1
1
|
|
2
|
-
require 'pathname'
|
3
|
-
|
4
2
|
module Gemgem
|
5
3
|
class << self
|
6
|
-
attr_accessor :dir, :spec
|
4
|
+
attr_accessor :dir, :spec, :spec_create
|
7
5
|
end
|
8
6
|
|
9
7
|
module_function
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
})
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def gem_tag
|
23
|
-
spec.version.to_s
|
8
|
+
def gem_tag ; spec.version.to_s ; end
|
9
|
+
def gem_path ; "#{pkg_dir}/#{spec.name}-#{gem_tag}.gem"; end
|
10
|
+
def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
|
11
|
+
def pkg_dir ; "#{dir}/pkg" ; end
|
12
|
+
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
|
+
|
14
|
+
def init dir, &block
|
15
|
+
self.dir = dir
|
16
|
+
$LOAD_PATH.unshift("#{dir}/lib")
|
17
|
+
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
|
+
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
19
|
+
self.spec_create = block
|
24
20
|
end
|
25
21
|
|
26
|
-
def
|
27
|
-
|
22
|
+
def create
|
23
|
+
spec = Gem::Specification.new do |s|
|
24
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
25
|
+
s.files = gem_files
|
26
|
+
s.test_files = test_files
|
27
|
+
s.executables = bin_files
|
28
|
+
end
|
29
|
+
spec_create.call(spec)
|
30
|
+
self.spec = spec
|
28
31
|
end
|
29
32
|
|
30
33
|
def write
|
31
|
-
File.open(
|
32
|
-
f << split_lines(spec.to_ruby) }
|
34
|
+
File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
|
33
35
|
end
|
34
36
|
|
35
37
|
def split_lines ruby
|
36
|
-
ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
|
38
|
+
ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
|
37
39
|
if $2.index(',')
|
38
|
-
"#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
40
|
+
"#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
39
41
|
else
|
40
42
|
s
|
41
43
|
end
|
42
44
|
}
|
43
45
|
end
|
44
46
|
|
47
|
+
def strip_path path
|
48
|
+
strip_home_path(strip_cwd_path(path))
|
49
|
+
end
|
50
|
+
|
51
|
+
def strip_home_path path
|
52
|
+
path.sub(ENV['HOME'], '~')
|
53
|
+
end
|
54
|
+
|
55
|
+
def strip_cwd_path path
|
56
|
+
path.sub(Dir.pwd, '.')
|
57
|
+
end
|
58
|
+
|
59
|
+
def git *args
|
60
|
+
`git --git-dir=#{dir}/.git #{args.join(' ')}`
|
61
|
+
end
|
62
|
+
|
63
|
+
def sh_git *args
|
64
|
+
Rake.sh('git', "--git-dir=#{dir}/.git", *args)
|
65
|
+
end
|
66
|
+
|
67
|
+
def sh_gem *args
|
68
|
+
Rake.sh(Gem.ruby, '-S', 'gem', *args)
|
69
|
+
end
|
70
|
+
|
71
|
+
def glob path=dir
|
72
|
+
Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
|
73
|
+
end
|
74
|
+
|
45
75
|
def all_files
|
46
|
-
@all_files ||=
|
47
|
-
|
48
|
-
|
76
|
+
@all_files ||= fold_files(glob).sort
|
77
|
+
end
|
78
|
+
|
79
|
+
def fold_files files
|
80
|
+
files.inject([]){ |r, path|
|
81
|
+
if File.file?(path) && path !~ %r{/\.git(/|$)} &&
|
82
|
+
(rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
|
83
|
+
r << rpath
|
84
|
+
elsif File.symlink?(path) # walk into symlinks...
|
85
|
+
r.concat(fold_files(glob(File.expand_path(path,
|
86
|
+
File.readlink(path)))))
|
49
87
|
else
|
50
|
-
|
88
|
+
r
|
51
89
|
end
|
52
|
-
}
|
90
|
+
}
|
53
91
|
end
|
54
92
|
|
55
93
|
def gem_files
|
56
|
-
@gem_files ||= all_files
|
94
|
+
@gem_files ||= all_files.reject{ |f|
|
95
|
+
f =~ ignored_pattern && !git_files.include?(f)
|
96
|
+
}
|
57
97
|
end
|
58
98
|
|
59
|
-
def
|
60
|
-
@
|
61
|
-
|
99
|
+
def test_files
|
100
|
+
@test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
101
|
+
end
|
102
|
+
|
103
|
+
def bin_files
|
104
|
+
@bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
62
105
|
end
|
63
106
|
|
64
107
|
def git_files
|
65
108
|
@git_files ||= if File.exist?("#{dir}/.git")
|
66
|
-
|
109
|
+
git('ls-files').split("\n")
|
67
110
|
else
|
68
111
|
[]
|
69
112
|
end
|
70
113
|
end
|
71
114
|
|
72
|
-
|
73
|
-
|
74
|
-
path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
|
75
|
-
path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
|
115
|
+
def ignored_files
|
116
|
+
@ignored_files ||= all_files.grep(ignored_pattern)
|
76
117
|
end
|
77
118
|
|
78
|
-
def
|
79
|
-
@
|
80
|
-
|
81
|
-
|
82
|
-
|
119
|
+
def ignored_pattern
|
120
|
+
@ignored_pattern ||= if gitignore.empty?
|
121
|
+
/^$/
|
122
|
+
else
|
123
|
+
Regexp.new(expand_patterns(gitignore).join('|'))
|
124
|
+
end
|
83
125
|
end
|
84
126
|
|
85
127
|
def expand_patterns pathes
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
Dir[path] +
|
92
|
-
Pathname.new(File.dirname(path)).children.select(&:directory?).
|
93
|
-
map{ |prefix| "#{prefix}/#{File.basename(path)}" })
|
94
|
-
end
|
95
|
-
}.flatten
|
128
|
+
# http://git-scm.com/docs/gitignore
|
129
|
+
pathes.flat_map{ |path|
|
130
|
+
# we didn't implement negative pattern for now
|
131
|
+
Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
|
132
|
+
}
|
96
133
|
end
|
97
134
|
|
98
135
|
def gitignore
|
99
|
-
if File.exist?(path = "#{dir}/.gitignore")
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
136
|
+
@gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
|
137
|
+
File.read(path).lines.
|
138
|
+
reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
|
139
|
+
else
|
140
|
+
[]
|
141
|
+
end
|
104
142
|
end
|
105
143
|
end
|
106
144
|
|
@@ -108,22 +146,37 @@ namespace :gem do
|
|
108
146
|
|
109
147
|
desc 'Install gem'
|
110
148
|
task :install => [:build] do
|
111
|
-
|
149
|
+
Gemgem.sh_gem('install', Gemgem.gem_path)
|
112
150
|
end
|
113
151
|
|
114
152
|
desc 'Build gem'
|
115
153
|
task :build => [:spec] do
|
116
|
-
|
117
|
-
|
118
|
-
|
154
|
+
require 'fileutils'
|
155
|
+
require 'rubygems/package'
|
156
|
+
gem = nil
|
157
|
+
Dir.chdir(Gemgem.dir) do
|
158
|
+
gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
|
159
|
+
FileUtils.mkdir_p(Gemgem.pkg_dir)
|
160
|
+
FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
|
161
|
+
end
|
162
|
+
puts "\e[35mGem built: \e[33m" \
|
163
|
+
"#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
|
164
|
+
end
|
165
|
+
|
166
|
+
desc 'Generate gemspec'
|
167
|
+
task :spec do
|
168
|
+
Gemgem.create
|
169
|
+
Gemgem.write
|
119
170
|
end
|
120
171
|
|
121
172
|
desc 'Release gem'
|
122
173
|
task :release => [:spec, :check, :build] do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
174
|
+
Gemgem.module_eval do
|
175
|
+
sh_git('tag', Gemgem.gem_tag)
|
176
|
+
sh_git('push')
|
177
|
+
sh_git('push', '--tags')
|
178
|
+
sh_gem('push', Gemgem.gem_path)
|
179
|
+
end
|
127
180
|
end
|
128
181
|
|
129
182
|
task :check do
|
@@ -146,11 +199,35 @@ end # of gem namespace
|
|
146
199
|
|
147
200
|
desc 'Run tests in memory'
|
148
201
|
task :test do
|
149
|
-
|
150
|
-
|
202
|
+
next if Gemgem.test_files.empty?
|
203
|
+
|
204
|
+
Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
|
151
205
|
Test::Unit::Runner.autorun
|
152
206
|
end
|
153
207
|
|
208
|
+
desc 'Trash ignored files'
|
209
|
+
task :clean => ['gem:spec'] do
|
210
|
+
next if Gemgem.ignored_files.empty?
|
211
|
+
|
212
|
+
require 'fileutils'
|
213
|
+
trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
|
214
|
+
puts "Move the following files into:" \
|
215
|
+
" \e[35m#{Gemgem.strip_path(trash)}\e[33m"
|
216
|
+
|
217
|
+
Gemgem.ignored_files.each do |file|
|
218
|
+
from = "#{Gemgem.dir}/#{file}"
|
219
|
+
to = "#{trash}/#{File.dirname(file)}"
|
220
|
+
puts Gemgem.strip_path(from)
|
221
|
+
|
222
|
+
FileUtils.mkdir_p(to)
|
223
|
+
FileUtils.mv(from, to)
|
224
|
+
end
|
225
|
+
|
226
|
+
print "\e[0m"
|
227
|
+
end
|
228
|
+
|
154
229
|
task :default do
|
155
|
-
|
230
|
+
# Is there a reliable way to do this in the current process?
|
231
|
+
# It failed miserably before between Rake versions...
|
232
|
+
exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
|
156
233
|
end
|
data/test/test_basic.rb
CHANGED
@@ -12,18 +12,18 @@ class TestBasic < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
sin="utf-8:utf-8,ascii"
|
14
14
|
sout=Bsdconv.insert_phase(sin, "upper", Bsdconv::INTER, 1)
|
15
|
-
assert_equal "
|
15
|
+
assert_equal "utf-8:upper:utf-8,ascii", sout
|
16
16
|
|
17
17
|
sin=sout
|
18
18
|
sout=Bsdconv.replace_phase(sin, "full", Bsdconv::INTER, 1)
|
19
|
-
assert_equal "
|
19
|
+
assert_equal "utf-8:full:utf-8,ascii", sout
|
20
20
|
|
21
21
|
sin=sout
|
22
22
|
sout=Bsdconv.replace_codec(sin, "big5", 2, 1)
|
23
|
-
assert_equal "
|
23
|
+
assert_equal "utf-8:full:utf-8,big5", sout
|
24
24
|
|
25
25
|
sin=sout
|
26
26
|
sout=Bsdconv.insert_codec(sin, "ascii", 0, 1)
|
27
|
-
assert_equal "
|
27
|
+
assert_equal "utf-8,ascii:full:utf-8,big5", sout
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-bsdconv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.1
|
4
|
+
version: 11.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Buganini Q
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ruby wrapper for bsdconv. bsdconv is a BSD licensed charset/encoding
|
14
14
|
converter library with more functionalities than libiconv
|
@@ -18,12 +18,16 @@ extensions:
|
|
18
18
|
- ext/ruby-bsdconv/extconf.rb
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- .gitignore
|
22
|
-
- README
|
21
|
+
- ".gitignore"
|
22
|
+
- README.md
|
23
23
|
- Rakefile
|
24
|
-
-
|
25
|
-
- example/
|
26
|
-
- example/
|
24
|
+
- doc/api.rst
|
25
|
+
- example/example_chunk.rb
|
26
|
+
- example/example_conv.rb
|
27
|
+
- example/example_conv_file.rb
|
28
|
+
- example/example_ctl.rb
|
29
|
+
- example/example_insert_replace.rb
|
30
|
+
- example/example_modules.rb
|
27
31
|
- ext/ruby-bsdconv/bsdconv.c
|
28
32
|
- ext/ruby-bsdconv/extconf.rb
|
29
33
|
- ruby-bsdconv.gemspec
|
@@ -39,17 +43,17 @@ require_paths:
|
|
39
43
|
- lib
|
40
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
45
|
requirements:
|
42
|
-
- -
|
46
|
+
- - ">="
|
43
47
|
- !ruby/object:Gem::Version
|
44
48
|
version: '0'
|
45
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
50
|
requirements:
|
47
|
-
- -
|
51
|
+
- - ">="
|
48
52
|
- !ruby/object:Gem::Version
|
49
53
|
version: '0'
|
50
54
|
requirements: []
|
51
55
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.2.2
|
53
57
|
signing_key:
|
54
58
|
specification_version: 4
|
55
59
|
summary: ruby wrapper for bsdconv
|
data/README
DELETED
data/example/example2.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bsdconv'
|
4
|
-
|
5
|
-
c=Bsdconv.new('utf-8:utf-8')
|
6
|
-
|
7
|
-
if c.nil?
|
8
|
-
abort(Bsdconv.error())
|
9
|
-
end
|
10
|
-
|
11
|
-
c.insert_phase('full',Bsdconv::INTER, 1)
|
12
|
-
puts c.conv('test')
|
13
|
-
|
14
|
-
p Bsdconv.codec_check(Bsdconv::FROM, "_utf-8")
|
15
|
-
p Bsdconv.codec_check(Bsdconv::INTER, "_utf-8")
|
16
|
-
puts 'From:'
|
17
|
-
p Bsdconv.codecs_list(Bsdconv::FROM)
|
18
|
-
puts 'Inter:'
|
19
|
-
p Bsdconv.codecs_list(Bsdconv::INTER)
|
20
|
-
puts 'To:'
|
21
|
-
p Bsdconv.codecs_list(Bsdconv::TO)
|