iconv 0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/BSDL +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +56 -0
- data/README.md +75 -0
- data/Rakefile +38 -0
- data/ext/iconv/depend +2 -0
- data/ext/iconv/extconf.rb +5 -2
- data/ext/iconv/iconv.c +578 -273
- data/iconv.gemspec +20 -0
- data/lib/iconv/version.rb +3 -0
- data/lib/iconv.rb +6 -0
- data/test/test_basic.rb +59 -0
- data/test/test_option.rb +43 -0
- data/test/test_partial.rb +41 -0
- data/test/utils.rb +23 -0
- metadata +46 -46
data/.gitignore
ADDED
data/BSDL
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Iconv
|
2
|
+
|
3
|
+
iconv wrapper, used to be ext/iconv
|
4
|
+
|
5
|
+
## Abstract
|
6
|
+
|
7
|
+
Iconv is a wrapper class for the UNIX 95 <code>iconv()</code> function family,
|
8
|
+
which translates string between various encoding systems.
|
9
|
+
|
10
|
+
See Open Group's on-line documents for more details.
|
11
|
+
* <code>iconv.h</code>: http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html
|
12
|
+
* <code>iconv_open()</code>: http://www.opengroup.org/onlinepubs/007908799/xsh/iconv_open.html
|
13
|
+
* <code>iconv()</code>: http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.html
|
14
|
+
* <code>iconv_close()</code>: http://www.opengroup.org/onlinepubs/007908799/xsh/iconv_close.html
|
15
|
+
|
16
|
+
Which coding systems are available is platform-dependent.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
gem 'iconv'
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install iconv
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
1. Simple conversion between two charsets.
|
35
|
+
|
36
|
+
converted_text = Iconv.conv('iso-8859-15', 'utf-8', text)
|
37
|
+
|
38
|
+
2. Instantiate a new Iconv and use method Iconv#iconv.
|
39
|
+
|
40
|
+
cd = Iconv.new(to, from)
|
41
|
+
begin
|
42
|
+
input.each { |s| output << cd.iconv(s) }
|
43
|
+
output << cd.iconv(nil) # Don't forget this!
|
44
|
+
ensure
|
45
|
+
cd.close
|
46
|
+
end
|
47
|
+
|
48
|
+
3. Invoke Iconv.open with a block.
|
49
|
+
|
50
|
+
Iconv.open(to, from) do |cd|
|
51
|
+
input.each { |s| output << cd.iconv(s) }
|
52
|
+
output << cd.iconv(nil)
|
53
|
+
end
|
54
|
+
|
55
|
+
4. Shorthand for (3).
|
56
|
+
|
57
|
+
Iconv.iconv(to, from, *input.to_a)
|
58
|
+
|
59
|
+
## Attentions
|
60
|
+
|
61
|
+
Even if some extentions of implementation dependent are useful,
|
62
|
+
DON'T USE those extentions in libraries and scripts to widely distribute.
|
63
|
+
If you want to use those feature, use String#encode.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
Ruby License/2-clause BSDL
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
NAME = 'iconv'
|
6
|
+
|
7
|
+
# rule to build the extension: this says
|
8
|
+
# that the extension should be rebuilt
|
9
|
+
# after any change to the files in ext
|
10
|
+
file "lib/#{NAME}/#{NAME}.so" =>
|
11
|
+
Dir.glob("ext/#{NAME}/*{.rb,.c}") do
|
12
|
+
Dir.chdir("ext/#{NAME}") do
|
13
|
+
# this does essentially the same thing
|
14
|
+
# as what RubyGems does
|
15
|
+
ruby "extconf.rb"
|
16
|
+
sh "make"
|
17
|
+
end
|
18
|
+
cp "ext/#{NAME}/#{NAME}.so", "lib/#{NAME}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# make the :test task depend on the shared
|
22
|
+
# object, so it will be built automatically
|
23
|
+
# before running the tests
|
24
|
+
task :test => "lib/#{NAME}/#{NAME}.so"
|
25
|
+
|
26
|
+
# use 'rake clean' and 'rake clobber' to
|
27
|
+
# easily delete generated files
|
28
|
+
CLEAN.include('ext/**/*{.o,.log,.so}')
|
29
|
+
CLEAN.include('ext/**/Makefile')
|
30
|
+
CLOBBER.include('lib/**/*.so')
|
31
|
+
|
32
|
+
# the same as before
|
33
|
+
Rake::TestTask.new do |t|
|
34
|
+
t.libs << 'test'
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Run tests"
|
38
|
+
task :default => :test
|
data/ext/iconv/depend
ADDED
data/ext/iconv/extconf.rb
CHANGED
@@ -7,6 +7,7 @@ conf = with_config("config-charset", enable_config("config-charset", conf))
|
|
7
7
|
|
8
8
|
if have_func("iconv", "iconv.h") or
|
9
9
|
have_library("iconv", "iconv", "iconv.h")
|
10
|
+
check_signedness("size_t")
|
10
11
|
if checking_for("const of iconv() 2nd argument") do
|
11
12
|
create_tmpsrc(cpp_include("iconv.h") + "---> iconv(cd,0,0,0,0) <---")
|
12
13
|
src = xpopen(cpp_command("")) {|f|f.read}
|
@@ -23,6 +24,8 @@ if have_func("iconv", "iconv.h") or
|
|
23
24
|
end
|
24
25
|
$defs.push('-DICONV_INPTR_CONST')
|
25
26
|
end
|
27
|
+
have_func("iconvlist", "iconv.h")
|
28
|
+
have_func("__iconv_free_list", "iconv.h")
|
26
29
|
if conf
|
27
30
|
prefix = '$(srcdir)'
|
28
31
|
prefix = $nmake ? "{#{prefix}}" : "#{prefix}/"
|
@@ -40,7 +43,7 @@ if have_func("iconv", "iconv.h") or
|
|
40
43
|
end
|
41
44
|
$cleanfiles << wrapper
|
42
45
|
end
|
43
|
-
create_makefile("iconv")
|
46
|
+
create_makefile("iconv/iconv")
|
44
47
|
if conf
|
45
48
|
open("Makefile", "a") do |mf|
|
46
49
|
mf.print("\nall: #{wrapper}\n\n#{wrapper}: #{prefix}charset_alias.rb")
|
@@ -48,4 +51,4 @@ if have_func("iconv", "iconv.h") or
|
|
48
51
|
mf.print("\n\t$(RUBY) $(srcdir)/charset_alias.rb #{conf} $@\n")
|
49
52
|
end
|
50
53
|
end
|
51
|
-
end
|
54
|
+
end
|