rubysl-jcode 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +8 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/jcode.rb +1 -0
- data/lib/rubysl/jcode.rb +2 -0
- data/lib/rubysl/jcode/jcode.rb +220 -0
- data/lib/{rubysl-jcode → rubysl/jcode}/version.rb +1 -1
- data/rubysl-jcode.gemspec +19 -18
- metadata +79 -86
- data/lib/rubysl-jcode.rb +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50824395dbd04c5fa597f4adee3783d5b74b81cc
|
4
|
+
data.tar.gz: 6c1029e744e020cf86889a43620a58ac4fa2797f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c94dcbfb1ac117af1550ce4224f4f5185054286b49de8a3914f528b770f87fc8bc2ab3dd584756d91a79b7117815cc9f20904dffbe43e6f0938dc3d77e52572
|
7
|
+
data.tar.gz: aa7bb8609c8dc1536c857c16fdf20179bd7a6356d4fd91e8a226640a8821e08fbd3f4425fcbdf1090b26ca0ee25d4935481d1472abc63a9ab4e58f5f1544cae0
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Rubysl::Jcode
|
2
2
|
|
3
3
|
TODO: Write a gem description
|
4
4
|
|
@@ -24,6 +24,6 @@ TODO: Write usage instructions here
|
|
24
24
|
|
25
25
|
1. Fork it
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am '
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/lib/jcode.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/jcode"
|
data/lib/rubysl/jcode.rb
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
# jcode.rb - ruby code to handle japanese (EUC/SJIS) string
|
2
|
+
|
3
|
+
if $VERBOSE && $KCODE == "NONE"
|
4
|
+
warn "Warning: $KCODE is NONE."
|
5
|
+
end
|
6
|
+
|
7
|
+
$vsave, $VERBOSE = $VERBOSE, false
|
8
|
+
class String
|
9
|
+
warn "feel free for some warnings:\n" if $VERBOSE
|
10
|
+
|
11
|
+
def _regex_quote(str)
|
12
|
+
str.gsub(/(\\[\[\]\-\\])|\\(.)|([\[\]\\])/) do
|
13
|
+
$1 || $2 || '\\' + $3
|
14
|
+
end
|
15
|
+
end
|
16
|
+
private :_regex_quote
|
17
|
+
|
18
|
+
PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'
|
19
|
+
PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]'
|
20
|
+
PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
|
21
|
+
|
22
|
+
RE_SJIS = Regexp.new(PATTERN_SJIS, 0, 'n')
|
23
|
+
RE_EUC = Regexp.new(PATTERN_EUC, 0, 'n')
|
24
|
+
RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n')
|
25
|
+
|
26
|
+
SUCC = {}
|
27
|
+
SUCC['s'] = Hash.new(1)
|
28
|
+
for i in 0 .. 0x3f
|
29
|
+
SUCC['s'][i.chr] = 0x40 - i
|
30
|
+
end
|
31
|
+
SUCC['s']["\x7e"] = 0x80 - 0x7e
|
32
|
+
SUCC['s']["\xfd"] = 0x100 - 0xfd
|
33
|
+
SUCC['s']["\xfe"] = 0x100 - 0xfe
|
34
|
+
SUCC['s']["\xff"] = 0x100 - 0xff
|
35
|
+
SUCC['e'] = Hash.new(1)
|
36
|
+
for i in 0 .. 0xa0
|
37
|
+
SUCC['e'][i.chr] = 0xa1 - i
|
38
|
+
end
|
39
|
+
SUCC['e']["\xfe"] = 2
|
40
|
+
SUCC['u'] = Hash.new(1)
|
41
|
+
for i in 0 .. 0x7f
|
42
|
+
SUCC['u'][i.chr] = 0x80 - i
|
43
|
+
end
|
44
|
+
SUCC['u']["\xbf"] = 0x100 - 0xbf
|
45
|
+
|
46
|
+
def mbchar?
|
47
|
+
case $KCODE[0]
|
48
|
+
when ?s, ?S
|
49
|
+
self =~ RE_SJIS
|
50
|
+
when ?e, ?E
|
51
|
+
self =~ RE_EUC
|
52
|
+
when ?u, ?U
|
53
|
+
self =~ RE_UTF8
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def end_regexp
|
60
|
+
case $KCODE[0]
|
61
|
+
when ?s, ?S
|
62
|
+
/#{PATTERN_SJIS}$/on
|
63
|
+
when ?e, ?E
|
64
|
+
/#{PATTERN_EUC}$/on
|
65
|
+
when ?u, ?U
|
66
|
+
/#{PATTERN_UTF8}$/on
|
67
|
+
else
|
68
|
+
/.$/on
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
alias original_succ! succ!
|
73
|
+
private :original_succ!
|
74
|
+
|
75
|
+
alias original_succ succ
|
76
|
+
private :original_succ
|
77
|
+
|
78
|
+
def succ!
|
79
|
+
reg = end_regexp
|
80
|
+
if $KCODE != 'NONE' && self =~ reg
|
81
|
+
succ_table = SUCC[$KCODE[0,1].downcase]
|
82
|
+
begin
|
83
|
+
self[-1] += succ_table[self[-1]]
|
84
|
+
self[-2] += 1 if self[-1] == 0
|
85
|
+
end while self !~ reg
|
86
|
+
self
|
87
|
+
else
|
88
|
+
original_succ!
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def succ
|
93
|
+
str = self.dup
|
94
|
+
str.succ! or str
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def _expand_ch str
|
100
|
+
a = []
|
101
|
+
str.scan(/(?:\\(.)|([^\\]))-(?:\\(.)|([^\\]))|(?:\\(.)|(.))/m) do
|
102
|
+
from = $1 || $2
|
103
|
+
to = $3 || $4
|
104
|
+
one = $5 || $6
|
105
|
+
if one
|
106
|
+
a.push one
|
107
|
+
elsif from.length != to.length
|
108
|
+
next
|
109
|
+
elsif from.length == 1
|
110
|
+
from[0].upto(to[0]) { |c| a.push c.chr }
|
111
|
+
else
|
112
|
+
from.upto(to) { |c| a.push c }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
a
|
116
|
+
end
|
117
|
+
|
118
|
+
def expand_ch_hash from, to
|
119
|
+
h = {}
|
120
|
+
afrom = _expand_ch(from)
|
121
|
+
ato = _expand_ch(to)
|
122
|
+
afrom.each_with_index do |x,i| h[x] = ato[i] || ato[-1] end
|
123
|
+
h
|
124
|
+
end
|
125
|
+
|
126
|
+
HashCache = {}
|
127
|
+
TrPatternCache = {}
|
128
|
+
DeletePatternCache = {}
|
129
|
+
SqueezePatternCache = {}
|
130
|
+
|
131
|
+
public
|
132
|
+
|
133
|
+
def tr!(from, to)
|
134
|
+
return nil if from == ""
|
135
|
+
return self.delete!(from) if to == ""
|
136
|
+
|
137
|
+
pattern = TrPatternCache[from] ||= /[#{_regex_quote(from)}]/
|
138
|
+
if from[0] == ?^
|
139
|
+
last = /.$/.match(to)[0]
|
140
|
+
self.gsub!(pattern, last)
|
141
|
+
else
|
142
|
+
h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
|
143
|
+
self.gsub!(pattern) do |c| h[c] end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def tr(from, to)
|
148
|
+
(str = self.dup).tr!(from, to) or str
|
149
|
+
end
|
150
|
+
|
151
|
+
def delete!(del)
|
152
|
+
return nil if del == ""
|
153
|
+
self.gsub!(DeletePatternCache[del] ||= /[#{_regex_quote(del)}]+/, '')
|
154
|
+
end
|
155
|
+
|
156
|
+
def delete(del)
|
157
|
+
(str = self.dup).delete!(del) or str
|
158
|
+
end
|
159
|
+
|
160
|
+
def squeeze!(del=nil)
|
161
|
+
return nil if del == ""
|
162
|
+
pattern =
|
163
|
+
if del
|
164
|
+
SqueezePatternCache[del] ||= /([#{_regex_quote(del)}])\1+/
|
165
|
+
else
|
166
|
+
/(.|\n)\1+/
|
167
|
+
end
|
168
|
+
self.gsub!(pattern, '\1')
|
169
|
+
end
|
170
|
+
|
171
|
+
def squeeze(del=nil)
|
172
|
+
(str = self.dup).squeeze!(del) or str
|
173
|
+
end
|
174
|
+
|
175
|
+
def tr_s!(from, to)
|
176
|
+
return self.delete!(from) if to.length == 0
|
177
|
+
|
178
|
+
pattern = SqueezePatternCache[from] ||= /([#{_regex_quote(from)}])\1*/
|
179
|
+
if from[0] == ?^
|
180
|
+
last = /.$/.match(to)[0]
|
181
|
+
self.gsub!(pattern, last)
|
182
|
+
else
|
183
|
+
h = HashCache[from + "1-0" + to] ||= expand_ch_hash(from, to)
|
184
|
+
self.gsub!(pattern) do h[$1] end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def tr_s(from, to)
|
189
|
+
(str = self.dup).tr_s!(from,to) or str
|
190
|
+
end
|
191
|
+
|
192
|
+
def chop!
|
193
|
+
self.gsub!(/(?:.|\r?\n)\z/, '')
|
194
|
+
end
|
195
|
+
|
196
|
+
def chop
|
197
|
+
(str = self.dup).chop! or str
|
198
|
+
end
|
199
|
+
|
200
|
+
def jlength
|
201
|
+
self.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
|
202
|
+
end
|
203
|
+
alias jsize jlength
|
204
|
+
|
205
|
+
def jcount(str)
|
206
|
+
self.delete("^#{str}").jlength
|
207
|
+
end
|
208
|
+
|
209
|
+
def each_char
|
210
|
+
if block_given?
|
211
|
+
scan(/./m) do |x|
|
212
|
+
yield x
|
213
|
+
end
|
214
|
+
else
|
215
|
+
scan(/./m)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
$VERBOSE = $vsave
|
data/rubysl-jcode.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/jcode/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-jcode"
|
6
|
+
spec.version = RubySL::Jcode::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library jcode.}
|
10
|
+
spec.summary = %q{Ruby standard library jcode.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-jcode"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = RubySL::Jcode::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
22
23
|
end
|
metadata
CHANGED
@@ -1,118 +1,111 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-jcode
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brian Shirai
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
26
24
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
version: "1.0"
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
36
28
|
name: rake
|
37
|
-
|
38
|
-
|
39
|
-
none: false
|
40
|
-
requirements:
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 10
|
46
|
-
- 0
|
47
|
-
version: "10.0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
48
34
|
type: :development
|
49
|
-
|
50
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
51
42
|
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
52
49
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubysl-prettyprint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
56
59
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
segments:
|
60
|
-
- 1
|
61
|
-
- 5
|
62
|
-
version: "1.5"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
63
62
|
type: :development
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: Ruby standard library jcode.
|
70
|
+
email:
|
67
71
|
- brixen@gmail.com
|
68
72
|
executables: []
|
69
|
-
|
70
73
|
extensions: []
|
71
|
-
|
72
74
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
files:
|
75
|
+
files:
|
75
76
|
- .gitignore
|
77
|
+
- .travis.yml
|
76
78
|
- Gemfile
|
77
79
|
- LICENSE
|
78
80
|
- README.md
|
79
81
|
- Rakefile
|
80
|
-
- lib/
|
81
|
-
- lib/rubysl
|
82
|
+
- lib/jcode.rb
|
83
|
+
- lib/rubysl/jcode.rb
|
84
|
+
- lib/rubysl/jcode/jcode.rb
|
85
|
+
- lib/rubysl/jcode/version.rb
|
82
86
|
- rubysl-jcode.gemspec
|
83
|
-
homepage:
|
84
|
-
licenses:
|
85
|
-
|
87
|
+
homepage: https://github.com/rubysl/rubysl-jcode
|
88
|
+
licenses:
|
89
|
+
- BSD
|
90
|
+
metadata: {}
|
86
91
|
post_install_message:
|
87
92
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
93
|
+
require_paths:
|
90
94
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
none: false
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
hash: 2002549777813010636
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
version: "0"
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
109
105
|
requirements: []
|
110
|
-
|
111
106
|
rubyforge_project:
|
112
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.0.7
|
113
108
|
signing_key:
|
114
|
-
specification_version:
|
115
|
-
summary: Ruby
|
109
|
+
specification_version: 4
|
110
|
+
summary: Ruby standard library jcode.
|
116
111
|
test_files: []
|
117
|
-
|
118
|
-
has_rdoc:
|