rchardet19 1.3.5

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.
Files changed (45) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +5 -0
  3. data/COPYING +504 -0
  4. data/Gemfile +4 -0
  5. data/README.markdown +63 -0
  6. data/Rakefile +29 -0
  7. data/lib/rchardet/big5freq.rb +927 -0
  8. data/lib/rchardet/big5prober.rb +42 -0
  9. data/lib/rchardet/chardistribution.rb +237 -0
  10. data/lib/rchardet/charsetgroupprober.rb +112 -0
  11. data/lib/rchardet/charsetprober.rb +75 -0
  12. data/lib/rchardet/codingstatemachine.rb +65 -0
  13. data/lib/rchardet/constants.rb +42 -0
  14. data/lib/rchardet/escprober.rb +89 -0
  15. data/lib/rchardet/escsm.rb +244 -0
  16. data/lib/rchardet/eucjpprober.rb +88 -0
  17. data/lib/rchardet/euckrfreq.rb +596 -0
  18. data/lib/rchardet/euckrprober.rb +42 -0
  19. data/lib/rchardet/euctwfreq.rb +430 -0
  20. data/lib/rchardet/euctwprober.rb +42 -0
  21. data/lib/rchardet/gb2312freq.rb +474 -0
  22. data/lib/rchardet/gb2312prober.rb +42 -0
  23. data/lib/rchardet/hebrewprober.rb +289 -0
  24. data/lib/rchardet/jisfreq.rb +570 -0
  25. data/lib/rchardet/jpcntx.rb +229 -0
  26. data/lib/rchardet/langbulgarianmodel.rb +229 -0
  27. data/lib/rchardet/langcyrillicmodel.rb +330 -0
  28. data/lib/rchardet/langgreekmodel.rb +227 -0
  29. data/lib/rchardet/langhebrewmodel.rb +202 -0
  30. data/lib/rchardet/langhungarianmodel.rb +226 -0
  31. data/lib/rchardet/langthaimodel.rb +201 -0
  32. data/lib/rchardet/latin1prober.rb +147 -0
  33. data/lib/rchardet/mbcharsetprober.rb +89 -0
  34. data/lib/rchardet/mbcsgroupprober.rb +47 -0
  35. data/lib/rchardet/mbcssm.rb +542 -0
  36. data/lib/rchardet/sbcharsetprober.rb +124 -0
  37. data/lib/rchardet/sbcsgroupprober.rb +58 -0
  38. data/lib/rchardet/sjisprober.rb +88 -0
  39. data/lib/rchardet/universaldetector.rb +168 -0
  40. data/lib/rchardet/utf8prober.rb +86 -0
  41. data/lib/rchardet19.rb +76 -0
  42. data/rchardet.gemspec +21 -0
  43. data/spec/rchardet19_spec.rb +39 -0
  44. data/spec/spec_helper.rb +6 -0
  45. metadata +114 -0
data/lib/rchardet19.rb ADDED
@@ -0,0 +1,76 @@
1
+ ######################## BEGIN LICENSE BLOCK ########################
2
+ # This library is free software; you can redistribute it and/or
3
+ # modify it under the terms of the GNU Lesser General Public
4
+ # License as published by the Free Software Foundation; either
5
+ # version 2.1 of the License, or (at your option) any later version.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
15
+ # 02110-1301 USA
16
+ ######################### END LICENSE BLOCK #########################
17
+
18
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
19
+
20
+ require 'rchardet/charsetprober'
21
+ require 'rchardet/mbcharsetprober'
22
+
23
+ require 'rchardet/big5freq'
24
+ require 'rchardet/big5prober'
25
+ require 'rchardet/chardistribution'
26
+ require 'rchardet/charsetgroupprober'
27
+
28
+ require 'rchardet/codingstatemachine'
29
+ require 'rchardet/constants'
30
+ require 'rchardet/escprober'
31
+ require 'rchardet/escsm'
32
+ require 'rchardet/eucjpprober'
33
+ require 'rchardet/euckrfreq'
34
+ require 'rchardet/euckrprober'
35
+ require 'rchardet/euctwfreq'
36
+ require 'rchardet/euctwprober'
37
+ require 'rchardet/gb2312freq'
38
+ require 'rchardet/gb2312prober'
39
+ require 'rchardet/hebrewprober'
40
+ require 'rchardet/jisfreq'
41
+ require 'rchardet/jpcntx'
42
+ require 'rchardet/langbulgarianmodel'
43
+ require 'rchardet/langcyrillicmodel'
44
+ require 'rchardet/langgreekmodel'
45
+ require 'rchardet/langhebrewmodel'
46
+ require 'rchardet/langhungarianmodel'
47
+ require 'rchardet/langthaimodel'
48
+ require 'rchardet/latin1prober'
49
+
50
+ require 'rchardet/mbcsgroupprober'
51
+ require 'rchardet/mbcssm'
52
+ require 'rchardet/sbcharsetprober'
53
+ require 'rchardet/sbcsgroupprober'
54
+ require 'rchardet/sjisprober'
55
+ require 'rchardet/universaldetector'
56
+ require 'rchardet/utf8prober'
57
+
58
+ module CharDet
59
+ VERSION = "1.3"
60
+ def CharDet.detect(aBuf, options = {})
61
+ if aBuf.nil?
62
+ raise Exception.new("Sorry, we can't guess the encoding on a nil object") if not options[:silent]
63
+ return self.create("", 0.0)
64
+ end
65
+
66
+ u = UniversalDetector.new
67
+ u.reset
68
+ u.feed(aBuf)
69
+ u.close
70
+ self.create(u.result['encoding'], u.result['confidence'])
71
+ end
72
+
73
+ def self.create(encoding, confidence)
74
+ Struct.new(:encoding, :confidence).new(encoding, confidence)
75
+ end
76
+ end
data/rchardet.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rchardet19"
6
+ s.version = "1.3.5"
7
+ s.authors = ["Jeff Hodges", "Édouard Brière", "Linus Oleander"]
8
+ s.email = "linus@oleander.nu"
9
+ s.homepage = "https://github.com/oleander/rchardet"
10
+ s.platform = Gem::Platform::RUBY
11
+ s.summary = "Character encoding auto-detection. Ruby 1.9 compat."
12
+ s.description = "Character encoding auto-detection in Ruby. This library is a port of the auto-detection code in Mozilla. It means taking a sequence of bytes in an unknown character encoding, and attempting to determine the encoding so you can read the text. It’s like cracking a code when you don’t have the decryption key."
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ s.has_rdoc = false # TODO: fix
18
+ s.extra_rdoc_files = ['README.markdown', 'COPYING']
19
+
20
+ s.add_development_dependency('rspec')
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe CharDet do
4
+ before(:each) do
5
+ @unknown = CharDet.detect("a random string")
6
+ end
7
+
8
+ it "should have two accessor methods" do
9
+ lambda {
10
+ @unknown.encoding
11
+ @unknown.confidence
12
+ }.should_not raise_error(NoMethodError)
13
+ end
14
+
15
+ it "should return the right content" do
16
+ @unknown.encoding.should eq("ascii")
17
+ @unknown.confidence.should be_instance_of(Float)
18
+ end
19
+
20
+ it "should return a nice message if nil is being passed" do
21
+ lambda {
22
+ CharDet.detect(nil)
23
+ }.should raise_error(Exception, "Sorry, we can't guess the encoding on a nil object")
24
+ end
25
+
26
+ it "should not raise an exception when passing an empty string" do
27
+ lambda {
28
+ CharDet.detect("")
29
+ }.should_not raise_error(Exception)
30
+ end
31
+
32
+ it "should be possible to make detect silent" do
33
+ lambda {
34
+ unknown = CharDet.detect(nil, :silent => true)
35
+ unknown.encoding.should be_empty
36
+ unknown.confidence.should eq(0.0)
37
+ }.should_not raise_error(Exception)
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'rchardet19'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rchardet19
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.3.5
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Hodges
9
+ - "\xC3\x89douard Bri\xC3\xA8re"
10
+ - Linus Oleander
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2011-02-17 00:00:00 +01:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: rspec
20
+ prerelease: false
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ type: :development
28
+ version_requirements: *id001
29
+ description: "Character encoding auto-detection in Ruby. This library is a port of the auto-detection code in Mozilla. It means taking a sequence of bytes in an unknown character encoding, and attempting to determine the encoding so you can read the text. It\xE2\x80\x99s like cracking a code when you don\xE2\x80\x99t have the decryption key."
30
+ email: linus@oleander.nu
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - README.markdown
37
+ - COPYING
38
+ files:
39
+ - .gitignore
40
+ - .rspec
41
+ - COPYING
42
+ - Gemfile
43
+ - Gemfile.lock
44
+ - README.markdown
45
+ - Rakefile
46
+ - lib/rchardet/big5freq.rb
47
+ - lib/rchardet/big5prober.rb
48
+ - lib/rchardet/chardistribution.rb
49
+ - lib/rchardet/charsetgroupprober.rb
50
+ - lib/rchardet/charsetprober.rb
51
+ - lib/rchardet/codingstatemachine.rb
52
+ - lib/rchardet/constants.rb
53
+ - lib/rchardet/escprober.rb
54
+ - lib/rchardet/escsm.rb
55
+ - lib/rchardet/eucjpprober.rb
56
+ - lib/rchardet/euckrfreq.rb
57
+ - lib/rchardet/euckrprober.rb
58
+ - lib/rchardet/euctwfreq.rb
59
+ - lib/rchardet/euctwprober.rb
60
+ - lib/rchardet/gb2312freq.rb
61
+ - lib/rchardet/gb2312prober.rb
62
+ - lib/rchardet/hebrewprober.rb
63
+ - lib/rchardet/jisfreq.rb
64
+ - lib/rchardet/jpcntx.rb
65
+ - lib/rchardet/langbulgarianmodel.rb
66
+ - lib/rchardet/langcyrillicmodel.rb
67
+ - lib/rchardet/langgreekmodel.rb
68
+ - lib/rchardet/langhebrewmodel.rb
69
+ - lib/rchardet/langhungarianmodel.rb
70
+ - lib/rchardet/langthaimodel.rb
71
+ - lib/rchardet/latin1prober.rb
72
+ - lib/rchardet/mbcharsetprober.rb
73
+ - lib/rchardet/mbcsgroupprober.rb
74
+ - lib/rchardet/mbcssm.rb
75
+ - lib/rchardet/sbcharsetprober.rb
76
+ - lib/rchardet/sbcsgroupprober.rb
77
+ - lib/rchardet/sjisprober.rb
78
+ - lib/rchardet/universaldetector.rb
79
+ - lib/rchardet/utf8prober.rb
80
+ - lib/rchardet19.rb
81
+ - rchardet.gemspec
82
+ - spec/rchardet19_spec.rb
83
+ - spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: https://github.com/oleander/rchardet
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.5.0
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Character encoding auto-detection. Ruby 1.9 compat.
112
+ test_files:
113
+ - spec/rchardet19_spec.rb
114
+ - spec/spec_helper.rb