mattetti-multibyte 0.0.1
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.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +28 -0
- data/README.txt +19 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/lib/multibyte.rb +15 -0
- data/lib/multibyte/chars.rb +135 -0
- data/lib/multibyte/generators/generate_tables.rb +148 -0
- data/lib/multibyte/handlers/passthru_handler.rb +9 -0
- data/lib/multibyte/handlers/utf8_handler.rb +564 -0
- data/lib/multibyte/handlers/utf8_handler_proc.rb +43 -0
- data/lib/multibyte/version.rb +9 -0
- data/lib/unicode.rb +66 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/multibyte_spec.rb +260 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +34 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.txt +39 -0
- metadata +86 -0
@@ -0,0 +1,260 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Chars" do
|
4
|
+
|
5
|
+
describe 'dealing with different string formats' do
|
6
|
+
|
7
|
+
string_format_examples.each do |type, string|
|
8
|
+
describe "a #{type} string" do
|
9
|
+
it "should have the chars method" do
|
10
|
+
string.should respond_to(:chars)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have the to_s method" do
|
14
|
+
string.should respond_to(:to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return an instance of Chars" do
|
18
|
+
string.chars.should be_an_instance_of(Multibyte::Chars)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not be changed when Chars#to_s is used" do
|
22
|
+
string.chars.to_s.should == string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
describe 'comparison' do
|
31
|
+
|
32
|
+
it "should be able to compare normal strings properly" do
|
33
|
+
'a'.should == 'a'
|
34
|
+
'a'.should_not == 'b'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be able to compare chars strings" do
|
38
|
+
"a".chars.should_not == "b".chars
|
39
|
+
"a".chars.should == "A".downcase.chars
|
40
|
+
"a".chars.should == "A".downcase
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not support strict comparison" do
|
44
|
+
string_format_examples[:utf8].eql?(string_format_examples[:utf8].chars).should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be compared by their enclosed string" do
|
48
|
+
string_format_examples[:utf8].should == string_format_examples[:utf8].chars
|
49
|
+
other_string = string_format_examples[:utf8].dup
|
50
|
+
other_string.should == string_format_examples[:utf8].chars
|
51
|
+
other_string.chars.should == string_format_examples[:utf8].chars
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be sortable based on their enclosed string" do
|
55
|
+
unsorted_strings = ['builder'.chars, 'armor'.chars, 'zebra'.chars]
|
56
|
+
unsorted_strings.sort!
|
57
|
+
['armor', 'builder', 'zebra'].should == unsorted_strings
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'utf8?' do
|
63
|
+
|
64
|
+
it "should know that UTF-8 strings are UTF-8" do
|
65
|
+
string_format_examples[:utf8].is_utf8?.should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should know that ascii strings are also valid UTF-8" do
|
69
|
+
string_format_examples[:ascii].is_utf8?.should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should know that bytestrings not valid utf-8" do
|
73
|
+
string_format_examples[:bytes].is_utf8?.should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'gsub' do
|
79
|
+
|
80
|
+
it "should be able to gsub" do
|
81
|
+
'café'.chars.gsub(/f/, 't').should == 'caté'
|
82
|
+
"我的影片".chars.gsub(/片/, 'X').should == "我的影X"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be to gsub even without the kcode setup" do
|
86
|
+
with_kcode('none') do
|
87
|
+
'éda'.chars.gsub(/d/, 'x').should == 'éxa'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'split' do
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
@word = "efficient"
|
97
|
+
@chars = ["e", "ffi", "c", "i", "e", "n", "t"]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should split by chars" do
|
101
|
+
@word.split(//).should == @chars
|
102
|
+
@chars.should == @word.chars.split(//)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return Chars instances" do
|
106
|
+
@word.chars.split(//).first.should be_an_instance_of(Multibyte::Chars)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'regexp matching' do
|
112
|
+
|
113
|
+
it "should should use String when kcode not set" do
|
114
|
+
with_kcode('none') do
|
115
|
+
(string_format_examples[:utf8].chars =~ /ffi/).should == 12
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should be unicode aware" do
|
120
|
+
with_kcode('UTF8') do
|
121
|
+
(string_format_examples[:utf8].chars =~ /ffi/).should == 9
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should return nil if no matches were found" do
|
126
|
+
with_kcode('UTF8') do
|
127
|
+
(''.chars =~ /\d+/).should be_nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'UTF8 pragma' do
|
134
|
+
|
135
|
+
it "should be on because KCODE is UTF8" do
|
136
|
+
if RUBY_VERSION < '1.9'
|
137
|
+
with_kcode('UTF8') do
|
138
|
+
" ".chars.send(:utf8_pragma?).should be_true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should be off because KCODE is UTF8" do
|
144
|
+
if RUBY_VERSION < '1.9'
|
145
|
+
with_kcode('none') do
|
146
|
+
" ".chars.send(:utf8_pragma?).should be_false
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should be OFF on Ruby 1.9" do
|
152
|
+
if RUBY_VERSION > '1.9'
|
153
|
+
" ".chars.send(:utf8_pragma?).shoud be_false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'handler settings' do
|
160
|
+
|
161
|
+
before(:each) do
|
162
|
+
@handler = ''.chars.handler
|
163
|
+
end
|
164
|
+
|
165
|
+
after(:all) do
|
166
|
+
Multibyte::Chars.handler = Multibyte::Handlers::UTF8Handler
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should process use and set handlers in the proper order" do
|
170
|
+
Multibyte::Chars.handler = :first
|
171
|
+
''.chars.handler.should == :first
|
172
|
+
|
173
|
+
Multibyte::Chars.handler = :second
|
174
|
+
''.chars.handler.should == :second
|
175
|
+
|
176
|
+
Multibyte::Chars.handler = @handler
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise an error" do
|
180
|
+
lambda{''.chars.handler.split}.should raise_error
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'method chaining' do
|
186
|
+
|
187
|
+
it "should return a chars instance when using downcase" do
|
188
|
+
''.chars.downcase.should be_an_instance_of(Multibyte::Chars)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should return a chars instance when using downcase" do
|
192
|
+
''.chars.strip.should be_an_instance_of(Multibyte::Chars)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should forward the chars instance down the down call path of chaining" do
|
196
|
+
stripped = ''.chars.downcase.strip
|
197
|
+
stripped.should be_an_instance_of(Multibyte::Chars)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should output a comparable result than a string result" do
|
201
|
+
" FOO ".chars.normalize.downcase.strip.should == 'foo'
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'passthrough_on_kcode' do
|
207
|
+
# The easiest way to check if the passthrough is in place is through #size
|
208
|
+
with_kcode('none') do
|
209
|
+
string_format_examples[:utf8].chars.size.should == 26
|
210
|
+
end
|
211
|
+
|
212
|
+
with_kcode('UTF8') do
|
213
|
+
string_format_examples[:utf8].chars.size.should == 17
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'desctructiveness' do
|
218
|
+
# Note that we're testing the destructiveness here and not the correct behaviour of the methods
|
219
|
+
|
220
|
+
before(:each) do
|
221
|
+
@str = 'ac'
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should be destructive when using Insert on a string" do
|
225
|
+
@str.chars.insert(1, 'b')
|
226
|
+
@str.should == 'abc'
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should be destructive when using reverse! on a string" do
|
230
|
+
@str.chars.reverse!
|
231
|
+
@str.should == 'ca'
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'resilience' do
|
237
|
+
|
238
|
+
it "should contain interpretable bytes" do
|
239
|
+
string_format_examples[:bytes].chars.size.should == 5
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should only yield interpretable bytes when a string is reversed" do
|
243
|
+
reversed = [0xb8, 0x17e, 0x8, 0x2c6, 0xa5].reverse.pack('U*')
|
244
|
+
string_format_examples[:bytes].chars.reverse.to_s.should == reversed
|
245
|
+
string_format_examples[:bytes].chars.reverse!.to_s.should == reversed
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe 'duck typing' do
|
250
|
+
|
251
|
+
it "should respond normally to String methods" do
|
252
|
+
'test'.chars.respond_to?(:strip).should be_true
|
253
|
+
'test'.chars.respond_to?(:normalize).should be_true
|
254
|
+
'test'.chars.respond_to?(:normalize!).should be_true
|
255
|
+
'test'.chars.respond_to?(:a_method_that_doesnt_exist).should be_false
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + "/../lib/multibyte"
|
10
|
+
|
11
|
+
module UnicodeHelper
|
12
|
+
|
13
|
+
def string_format_examples
|
14
|
+
{
|
15
|
+
:utf8 => "Abcd Блå ffi блa 埋",
|
16
|
+
:ascii => "asci ias c iia s",
|
17
|
+
:bytes => "\270\236\010\210\245"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def with_kcode(kcode)
|
22
|
+
old_kcode, $KCODE = $KCODE, kcode
|
23
|
+
begin
|
24
|
+
yield
|
25
|
+
ensure
|
26
|
+
$KCODE = old_kcode
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
Spec::Runner.configure do |config|
|
33
|
+
include UnicodeHelper
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
21
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/website/index.txt
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
h1. multibyte
|
2
|
+
|
3
|
+
h1. → 'multibyte'
|
4
|
+
|
5
|
+
|
6
|
+
h2. What
|
7
|
+
|
8
|
+
|
9
|
+
h2. Installing
|
10
|
+
|
11
|
+
<pre syntax="ruby">sudo gem install multibyte</pre>
|
12
|
+
|
13
|
+
h2. The basics
|
14
|
+
|
15
|
+
|
16
|
+
h2. Demonstration of usage
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
h2. Forum
|
21
|
+
|
22
|
+
"http://groups.google.com/group/multibyte":http://groups.google.com/group/multibyte
|
23
|
+
|
24
|
+
TODO - create Google Group - multibyte
|
25
|
+
|
26
|
+
h2. How to submit patches
|
27
|
+
|
28
|
+
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
29
|
+
|
30
|
+
The trunk repository is <code>svn://rubyforge.org/var/svn/multibyte/trunk</code> for anonymous access.
|
31
|
+
|
32
|
+
h2. License
|
33
|
+
|
34
|
+
This code is free to use under the terms of the MIT license.
|
35
|
+
|
36
|
+
h2. Contact
|
37
|
+
|
38
|
+
Comments are welcome. Send an email to "FIXME full name":mailto:FIXME email via the "forum":http://groups.google.com/group/multibyte
|
39
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattetti-multibyte
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Aimonetti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-28 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Multibyte support for Ruby
|
17
|
+
email:
|
18
|
+
- mattaimonetti@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.txt
|
25
|
+
- License.txt
|
26
|
+
- Manifest.txt
|
27
|
+
- README.txt
|
28
|
+
- website/index.txt
|
29
|
+
files:
|
30
|
+
- History.txt
|
31
|
+
- License.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
- Rakefile
|
35
|
+
- config/hoe.rb
|
36
|
+
- config/requirements.rb
|
37
|
+
- lib/multibyte.rb
|
38
|
+
- lib/multibyte/chars.rb
|
39
|
+
- lib/multibyte/generators/generate_tables.rb
|
40
|
+
- lib/multibyte/handlers/passthru_handler.rb
|
41
|
+
- lib/multibyte/handlers/utf8_handler.rb
|
42
|
+
- lib/multibyte/handlers/utf8_handler_proc.rb
|
43
|
+
- lib/multibyte/version.rb
|
44
|
+
- lib/unicode.rb
|
45
|
+
- log/debug.log
|
46
|
+
- script/destroy
|
47
|
+
- script/generate
|
48
|
+
- script/txt2html
|
49
|
+
- setup.rb
|
50
|
+
- spec/multibyte_spec.rb
|
51
|
+
- spec/spec.opts
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- tasks/deployment.rake
|
54
|
+
- tasks/environment.rake
|
55
|
+
- tasks/rspec.rake
|
56
|
+
- tasks/website.rake
|
57
|
+
- website/index.txt
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://multibyte.rubyforge.org
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --main
|
63
|
+
- README.txt
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: multibyte
|
81
|
+
rubygems_version: 1.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: Multibyte support for Ruby
|
85
|
+
test_files: []
|
86
|
+
|