rencode 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,4 @@
1
+
2
+ 0.1.0 (Jun 21, 2011)
3
+
4
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.2"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.2)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ x86-mingw32
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.2)
19
+ rcov
20
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Miquel Cubel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = rencode
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to rencode
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Miquel Cubel. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rencode"
18
+ gem.homepage = "http://github.com/micues/rencode"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Solve encoding problems}
21
+ gem.description = %Q{Code from diferent sources to UT8 or code text to acute}
22
+ gem.email = "mcubel@gmail.com"
23
+ gem.authors = ["Miquel Cubel"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rencode #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1 @@
1
+ require 'rencode/rencode'
@@ -0,0 +1,175 @@
1
+ # encoding: UTF-8
2
+ class RubyEncode
3
+
4
+ def REncode(textToCode,cleanLine=true,encodeFrom="ISO-8859-1",onErrorNil=true,reviewByte=false)
5
+ #Info: ISO-8859-1 is the default character set in most browsers.
6
+
7
+ if cleanLine
8
+ #Windows / Ubuntu common problems
9
+ textToCode = textToCode.gsub(/\r/,'')
10
+ textToCode = textToCode.gsub(/\n/,'')
11
+ end
12
+
13
+
14
+ begin
15
+ #Normal encoding
16
+ sanitized = textToCode.force_encoding(encodeFrom).encode!("UTF-8")
17
+ rescue
18
+ #CodePoint revision
19
+ textToCodeCodePoint = ""
20
+ textToCode.force_encoding(encodeFrom).each_codepoint { |cp|
21
+ begin
22
+ case cp
23
+ when 0 #know problems
24
+ textToCodeCodePoint = textToCodeCodePoint + ' '
25
+ else
26
+ #puts 'codePoint: ' + cp.to_s + ' ' + cp.chr
27
+ textToCodeCodePoint = textToCodeCodePoint + cp.chr.encode!("UTF-8")
28
+ end
29
+ rescue Exception => e
30
+ puts 'Error on codepoint: ' + cp.to_s
31
+
32
+ if onErrorNil
33
+ textToCodeCodePoint = nil
34
+ break cp
35
+ end
36
+ end
37
+ }
38
+
39
+ #Byte revision (use carefully)
40
+ reviewByte = false if textToCodeCodePoint == nil
41
+ if reviewByte
42
+ textToCodeByte = ""
43
+ textToCodeCodePoint.force_encoding("UTF-8").each_byte { |bt|
44
+ case bt
45
+ when 0 #know problems
46
+ textToCodeByte = textToCodeByte + ' '
47
+ else
48
+ #puts 'Byte: ' + bt.to_s.force_encoding("UTF-8") + ' ' + bt.chr
49
+ textToCodeByte = textToCodeByte + bt.chr
50
+ end
51
+ }
52
+ sanitized = textToCodeByte
53
+ else
54
+ textToCodeByte = textToCodeCodePoint
55
+ end
56
+ end
57
+
58
+ return sanitized.force_encoding("UTF-8")
59
+ end
60
+
61
+ def REncodeHTML(textToCode,htmlPrint=false)
62
+ #Info: http://www.w3schools.com/tags/ref_entities.asp
63
+ if textToCode == nil
64
+ textToCode = ''
65
+ else
66
+ if htmlPrint
67
+ textToCode = textToCode.gsub('"','&#34;')
68
+ textToCode = textToCode.gsub("'",'&#39;')
69
+ textToCode = textToCode.gsub('&','&#38;')
70
+ textToCode = textToCode.gsub('<','&#60;')
71
+ textToCode = textToCode.gsub('>','&#62;')
72
+ #textToCode = textToCode.gsub(' ','&#160;')
73
+ end
74
+
75
+ textToCode = textToCode.gsub('¡','&#161;')
76
+ textToCode = textToCode.gsub('¢','&#162;')
77
+ textToCode = textToCode.gsub('£','&#163;')
78
+ textToCode = textToCode.gsub('¤','&#164;')
79
+ textToCode = textToCode.gsub('¥','&#165;')
80
+ textToCode = textToCode.gsub('¦','&#166;')
81
+ textToCode = textToCode.gsub('§','&#167;')
82
+ textToCode = textToCode.gsub('¨','&#168;')
83
+ textToCode = textToCode.gsub('©','&#169;')
84
+ textToCode = textToCode.gsub('ª','&#170;')
85
+ textToCode = textToCode.gsub('«','&#171;')
86
+ textToCode = textToCode.gsub('¬','&#172;')
87
+ textToCode = textToCode.gsub('­','&#173;')
88
+ textToCode = textToCode.gsub('®','&#174;')
89
+ textToCode = textToCode.gsub('¯','&#175;')
90
+ textToCode = textToCode.gsub('°','&#176;')
91
+ textToCode = textToCode.gsub('±','&#177;')
92
+ textToCode = textToCode.gsub('²','&#178;')
93
+ textToCode = textToCode.gsub('³','&#179;')
94
+ textToCode = textToCode.gsub('´','&#180;')
95
+ textToCode = textToCode.gsub('µ','&#181;')
96
+ textToCode = textToCode.gsub('¶','&#182;')
97
+ textToCode = textToCode.gsub('·','&#183;')
98
+ textToCode = textToCode.gsub('¸','&#184;')
99
+ textToCode = textToCode.gsub('¹','&#185;')
100
+ textToCode = textToCode.gsub('º','&#186;')
101
+ textToCode = textToCode.gsub('»','&#187;')
102
+ textToCode = textToCode.gsub('¼','&#188;')
103
+ textToCode = textToCode.gsub('½','&#189;')
104
+ textToCode = textToCode.gsub('¾','&#190;')
105
+ textToCode = textToCode.gsub('¿','&#191;')
106
+ textToCode = textToCode.gsub('×','&#215;')
107
+ textToCode = textToCode.gsub('÷','&#247;')
108
+
109
+
110
+ textToCode = textToCode.gsub('À','&#192;')
111
+ textToCode = textToCode.gsub('Á','&#193;')
112
+ textToCode = textToCode.gsub('Â','&#194;')
113
+ textToCode = textToCode.gsub('Ã','&#195;')
114
+ textToCode = textToCode.gsub('Ä','&#196;')
115
+ textToCode = textToCode.gsub('Å','&#197;')
116
+ textToCode = textToCode.gsub('Æ','&#198;')
117
+ textToCode = textToCode.gsub('Ç','&#199;')
118
+ textToCode = textToCode.gsub('È','&#200;')
119
+ textToCode = textToCode.gsub('É','&#201;')
120
+ textToCode = textToCode.gsub('Ê','&#202;')
121
+ textToCode = textToCode.gsub('Ë','&#203;')
122
+ textToCode = textToCode.gsub('Ì','&#204;')
123
+ textToCode = textToCode.gsub('Í','&#205;')
124
+ textToCode = textToCode.gsub('Î','&#206;')
125
+ textToCode = textToCode.gsub('Ï','&#207;')
126
+ textToCode = textToCode.gsub('Ð','&#208;')
127
+ textToCode = textToCode.gsub('Ñ','&#209;')
128
+ textToCode = textToCode.gsub('Ò','&#210;')
129
+ textToCode = textToCode.gsub('Ó','&#211;')
130
+ textToCode = textToCode.gsub('Ô','&#212;')
131
+ textToCode = textToCode.gsub('Õ','&#213;')
132
+ textToCode = textToCode.gsub('Ö','&#214;')
133
+ textToCode = textToCode.gsub('Ø','&#216;')
134
+ textToCode = textToCode.gsub('Ù','&#217;')
135
+ textToCode = textToCode.gsub('Ú','&#218;')
136
+ textToCode = textToCode.gsub('Û','&#219;')
137
+ textToCode = textToCode.gsub('Ü','&#220;')
138
+ textToCode = textToCode.gsub('Ý','&#221;')
139
+ textToCode = textToCode.gsub('Þ','&#222;')
140
+ textToCode = textToCode.gsub('ß','&#223;')
141
+ textToCode = textToCode.gsub('à','&#224;')
142
+ textToCode = textToCode.gsub('á','&#225;')
143
+ textToCode = textToCode.gsub('â','&#226;')
144
+ textToCode = textToCode.gsub('ã','&#227;')
145
+ textToCode = textToCode.gsub('ä','&#228;')
146
+ textToCode = textToCode.gsub('å','&#229;')
147
+ textToCode = textToCode.gsub('æ','&#230;')
148
+ textToCode = textToCode.gsub('ç','&#231;')
149
+ textToCode = textToCode.gsub('è','&#232;')
150
+ textToCode = textToCode.gsub('é','&#233;')
151
+ textToCode = textToCode.gsub('ê','&#234;')
152
+ textToCode = textToCode.gsub('ë','&#235;')
153
+ textToCode = textToCode.gsub('ì','&#236;')
154
+ textToCode = textToCode.gsub('í','&#237;')
155
+ textToCode = textToCode.gsub('î','&#238;')
156
+ textToCode = textToCode.gsub('ï','&#239;')
157
+ textToCode = textToCode.gsub('ð','&#240;')
158
+ textToCode = textToCode.gsub('ñ','&#241;')
159
+ textToCode = textToCode.gsub('ò','&#242;')
160
+ textToCode = textToCode.gsub('ó','&#243;')
161
+ textToCode = textToCode.gsub('ô','&#244;')
162
+ textToCode = textToCode.gsub('õ','&#245;')
163
+ textToCode = textToCode.gsub('ö','&#246;')
164
+ textToCode = textToCode.gsub('ø','&#248;')
165
+ textToCode = textToCode.gsub('ù','&#249;')
166
+ textToCode = textToCode.gsub('ú','&#250;')
167
+ textToCode = textToCode.gsub('û','&#251;')
168
+ textToCode = textToCode.gsub('ü','&#252;')
169
+ textToCode = textToCode.gsub('ý','&#253;')
170
+ textToCode = textToCode.gsub('þ','&#254;')
171
+ textToCode = textToCode.gsub('ÿ','&#255;')
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rencode'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: ISO-8859-1
2
+ load 'REncode.rb'
3
+
4
+
5
+ file_read = File.new("test.txt")
6
+ file_write = File.new("test.txt.sanitized", "w:utf-8")
7
+
8
+ re = RubyEncode.new()
9
+
10
+
11
+ while (line = file_read.gets)
12
+ file_write.write(re.REncode(line) + "\n")
13
+ end
14
+
15
+ file_read.close
16
+ file_write.close
17
+
18
+
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRencode < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rencode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Miquel Cubel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-21 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ requirement: &23729580 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *23729580
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: &23720640 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *23720640
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ requirement: &23719356 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.6.2
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *23719356
48
+ - !ruby/object:Gem::Dependency
49
+ name: rcov
50
+ requirement: &23718168 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *23718168
59
+ description: Code from diferent sources to UT8 or code text to acute
60
+ email: mcubel@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - CHANGELOG.rdoc
65
+ - LICENSE.txt
66
+ - README.rdoc
67
+ files:
68
+ - .document
69
+ - CHANGELOG.rdoc
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.rdoc
74
+ - Rakefile
75
+ - VERSION
76
+ - lib/rencode.rb
77
+ - lib/rencode/rencode.rb
78
+ - test/helper.rb
79
+ - test/test.rb
80
+ - test/test.txt
81
+ - test/test.txt.sanitized
82
+ - test/test_rencode.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/micues/rencode
85
+ licenses:
86
+ - MIT
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ segments:
98
+ - 0
99
+ hash: -218573489
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.6.2
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Solve encoding problems
112
+ test_files: []