string_z2h 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +15 -0
- data/README.txt +52 -0
- data/lib/string_z2h/ascii.EUC +96 -0
- data/lib/string_z2h/ascii.SJIS +96 -0
- data/lib/string_z2h/ascii.UTF8 +98 -0
- data/lib/string_z2h/kana.EUC +89 -0
- data/lib/string_z2h/kana.SJIS +89 -0
- data/lib/string_z2h/kana.UTF8 +89 -0
- data/lib/string_z2h/version.rb +9 -0
- data/lib/string_z2h.rb +53 -0
- data/setup.rb +1585 -0
- data/test/test_helper.rb +2 -0
- data/test/test_string_z2h.rb +23 -0
- metadata +66 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Kazutaka Ueda, Ryota Maruko
|
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.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
lib/string_z2h.rb
|
6
|
+
lib/string_z2h/ascii.EUC
|
7
|
+
lib/string_z2h/ascii.SJIS
|
8
|
+
lib/string_z2h/ascii.UTF8
|
9
|
+
lib/string_z2h/kana.EUC
|
10
|
+
lib/string_z2h/kana.SJIS
|
11
|
+
lib/string_z2h/kana.UTF8
|
12
|
+
lib/string_z2h/version.rb
|
13
|
+
setup.rb
|
14
|
+
test/test_helper.rb
|
15
|
+
test/test_string_z2h.rb
|
data/README.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= string_z2h
|
2
|
+
|
3
|
+
* http://rubyforge.org/projects/stringz2h
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This library expands String class to convert 2byte character and 1byte character for Japanese Encoding.
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
$KCODE='u'
|
12
|
+
require "string_z2h"
|
13
|
+
"ABCアイウ".to_han() # => ABCアイウ
|
14
|
+
"ABCアイウ".to_han(:all) # => ABCアイウ
|
15
|
+
"ABCアイウ".to_han(:kana) # => ABCアイウ
|
16
|
+
"ABCアイウ".to_han(:ascii) # => ABCアイウ
|
17
|
+
|
18
|
+
"ABCアイウ".to_zen() # => "ABCアイウ"
|
19
|
+
"ABCアイウ".to_zen(:all) # => "ABCアイウ"
|
20
|
+
"ABCアイウ".to_zne(:kana) # => "ABCアイウ"
|
21
|
+
"ABCアイウ".to_zen(:ascii) # => "ABCアイウ"
|
22
|
+
|
23
|
+
"ゴラァ".to_han(:kana) #=> "ゴラァ"
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
* sudo gem install string_z2h
|
28
|
+
|
29
|
+
== LICENSE:
|
30
|
+
|
31
|
+
(The MIT License)
|
32
|
+
|
33
|
+
Copyright (c) 2008 Kazutaka Ueda, Ryota Maruko
|
34
|
+
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
36
|
+
a copy of this software and associated documentation files (the
|
37
|
+
'Software'), to deal in the Software without restriction, including
|
38
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
39
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
40
|
+
permit persons to whom the Software is furnished to do so, subject to
|
41
|
+
the following conditions:
|
42
|
+
|
43
|
+
The above copyright notice and this permission notice shall be
|
44
|
+
included in all copies or substantial portions of the Software.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
47
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
48
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
49
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
50
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
51
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
52
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,96 @@
|
|
1
|
+
��
|
2
|
+
�� !
|
3
|
+
�� "
|
4
|
+
�� #
|
5
|
+
�� $
|
6
|
+
�� %
|
7
|
+
�� &
|
8
|
+
�� '
|
9
|
+
�� (
|
10
|
+
�� )
|
11
|
+
�� *
|
12
|
+
�� +
|
13
|
+
�� ,
|
14
|
+
�� -
|
15
|
+
�� .
|
16
|
+
�� /
|
17
|
+
�� 0
|
18
|
+
�� 1
|
19
|
+
�� 2
|
20
|
+
�� 3
|
21
|
+
�� 4
|
22
|
+
�� 5
|
23
|
+
�� 6
|
24
|
+
�� 7
|
25
|
+
�� 8
|
26
|
+
�� 9
|
27
|
+
�� :
|
28
|
+
�� ;
|
29
|
+
�� <
|
30
|
+
�� =
|
31
|
+
�� >
|
32
|
+
�� ?
|
33
|
+
�� @
|
34
|
+
�� A
|
35
|
+
�� B
|
36
|
+
�� C
|
37
|
+
�� D
|
38
|
+
�� E
|
39
|
+
�� F
|
40
|
+
�� G
|
41
|
+
�� H
|
42
|
+
�� I
|
43
|
+
�� J
|
44
|
+
�� K
|
45
|
+
�� L
|
46
|
+
�� M
|
47
|
+
�� N
|
48
|
+
�� O
|
49
|
+
�� P
|
50
|
+
�� Q
|
51
|
+
�� R
|
52
|
+
�� S
|
53
|
+
�� T
|
54
|
+
�� U
|
55
|
+
�� V
|
56
|
+
�� W
|
57
|
+
�� X
|
58
|
+
�� Y
|
59
|
+
�� Z
|
60
|
+
�� [
|
61
|
+
�� \
|
62
|
+
�� ]
|
63
|
+
�� ^
|
64
|
+
�� _
|
65
|
+
�� `
|
66
|
+
�� a
|
67
|
+
�� b
|
68
|
+
�� c
|
69
|
+
�� d
|
70
|
+
�� e
|
71
|
+
�� f
|
72
|
+
�� g
|
73
|
+
�� h
|
74
|
+
�� i
|
75
|
+
�� j
|
76
|
+
�� k
|
77
|
+
�� l
|
78
|
+
�� m
|
79
|
+
�� n
|
80
|
+
�� o
|
81
|
+
�� p
|
82
|
+
�� q
|
83
|
+
�� r
|
84
|
+
�� s
|
85
|
+
�� t
|
86
|
+
�� u
|
87
|
+
�� v
|
88
|
+
�� w
|
89
|
+
�� x
|
90
|
+
�� y
|
91
|
+
�� z
|
92
|
+
�� {
|
93
|
+
�� |
|
94
|
+
�� }
|
95
|
+
�� ��
|
96
|
+
�� ~
|
@@ -0,0 +1,96 @@
|
|
1
|
+
�@
|
2
|
+
�I !
|
3
|
+
�h "
|
4
|
+
�� #
|
5
|
+
�� $
|
6
|
+
�� %
|
7
|
+
�� &
|
8
|
+
�f '
|
9
|
+
�i (
|
10
|
+
�j )
|
11
|
+
�� *
|
12
|
+
�{ +
|
13
|
+
�C ,
|
14
|
+
�| -
|
15
|
+
�D .
|
16
|
+
�^ /
|
17
|
+
�O 0
|
18
|
+
�P 1
|
19
|
+
�Q 2
|
20
|
+
�R 3
|
21
|
+
�S 4
|
22
|
+
�T 5
|
23
|
+
�U 6
|
24
|
+
�V 7
|
25
|
+
�W 8
|
26
|
+
�X 9
|
27
|
+
�F :
|
28
|
+
�G ;
|
29
|
+
�� <
|
30
|
+
�� =
|
31
|
+
�� >
|
32
|
+
�H ?
|
33
|
+
�� @
|
34
|
+
�` A
|
35
|
+
�a B
|
36
|
+
�b C
|
37
|
+
�c D
|
38
|
+
�d E
|
39
|
+
�e F
|
40
|
+
�f G
|
41
|
+
�g H
|
42
|
+
�h I
|
43
|
+
�i J
|
44
|
+
�j K
|
45
|
+
�k L
|
46
|
+
�l M
|
47
|
+
�m N
|
48
|
+
�n O
|
49
|
+
�o P
|
50
|
+
�p Q
|
51
|
+
�q R
|
52
|
+
�r S
|
53
|
+
�s T
|
54
|
+
�t U
|
55
|
+
�u V
|
56
|
+
�v W
|
57
|
+
�w X
|
58
|
+
�x Y
|
59
|
+
�y Z
|
60
|
+
�m [
|
61
|
+
�� \
|
62
|
+
�n ]
|
63
|
+
�O ^
|
64
|
+
�Q _
|
65
|
+
�M `
|
66
|
+
�� a
|
67
|
+
�� b
|
68
|
+
�� c
|
69
|
+
�� d
|
70
|
+
�� e
|
71
|
+
�� f
|
72
|
+
�� g
|
73
|
+
�� h
|
74
|
+
�� i
|
75
|
+
�� j
|
76
|
+
�� k
|
77
|
+
�� l
|
78
|
+
�� m
|
79
|
+
�� n
|
80
|
+
�� o
|
81
|
+
�� p
|
82
|
+
�� q
|
83
|
+
�� r
|
84
|
+
�� s
|
85
|
+
�� t
|
86
|
+
�� u
|
87
|
+
�� v
|
88
|
+
�� w
|
89
|
+
�� x
|
90
|
+
�� y
|
91
|
+
�� z
|
92
|
+
�o {
|
93
|
+
�b |
|
94
|
+
�p }
|
95
|
+
�E �
|
96
|
+
�` ~
|
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
! !
|
3
|
+
” "
|
4
|
+
# #
|
5
|
+
$ $
|
6
|
+
% %
|
7
|
+
& &
|
8
|
+
’ '
|
9
|
+
( (
|
10
|
+
) )
|
11
|
+
* *
|
12
|
+
+ +
|
13
|
+
, ,
|
14
|
+
- -
|
15
|
+
− -
|
16
|
+
. .
|
17
|
+
/ /
|
18
|
+
0 0
|
19
|
+
1 1
|
20
|
+
2 2
|
21
|
+
3 3
|
22
|
+
4 4
|
23
|
+
5 5
|
24
|
+
6 6
|
25
|
+
7 7
|
26
|
+
8 8
|
27
|
+
9 9
|
28
|
+
: :
|
29
|
+
; ;
|
30
|
+
< <
|
31
|
+
= =
|
32
|
+
> >
|
33
|
+
? ?
|
34
|
+
@ @
|
35
|
+
A A
|
36
|
+
B B
|
37
|
+
C C
|
38
|
+
D D
|
39
|
+
E E
|
40
|
+
F F
|
41
|
+
G G
|
42
|
+
H H
|
43
|
+
I I
|
44
|
+
J J
|
45
|
+
K K
|
46
|
+
L L
|
47
|
+
M M
|
48
|
+
N N
|
49
|
+
O O
|
50
|
+
P P
|
51
|
+
Q Q
|
52
|
+
R R
|
53
|
+
S S
|
54
|
+
T T
|
55
|
+
U U
|
56
|
+
V V
|
57
|
+
W W
|
58
|
+
X X
|
59
|
+
Y Y
|
60
|
+
Z Z
|
61
|
+
[ [
|
62
|
+
¥ \
|
63
|
+
] ]
|
64
|
+
^ ^
|
65
|
+
_ _
|
66
|
+
` `
|
67
|
+
a a
|
68
|
+
b b
|
69
|
+
c c
|
70
|
+
d d
|
71
|
+
e e
|
72
|
+
f f
|
73
|
+
g g
|
74
|
+
h h
|
75
|
+
i i
|
76
|
+
j j
|
77
|
+
k k
|
78
|
+
l l
|
79
|
+
m m
|
80
|
+
n n
|
81
|
+
o o
|
82
|
+
p p
|
83
|
+
q q
|
84
|
+
r r
|
85
|
+
s s
|
86
|
+
t t
|
87
|
+
u u
|
88
|
+
v v
|
89
|
+
w w
|
90
|
+
x x
|
91
|
+
y y
|
92
|
+
z z
|
93
|
+
{ {
|
94
|
+
| |
|
95
|
+
} }
|
96
|
+
・ ・
|
97
|
+
~ ~
|
98
|
+
〜 ~
|
@@ -0,0 +1,89 @@
|
|
1
|
+
�� ��
|
2
|
+
�� ��
|
3
|
+
�� ��
|
4
|
+
�� ��
|
5
|
+
�� ��
|
6
|
+
�� ��
|
7
|
+
�� ��
|
8
|
+
�� ��
|
9
|
+
�� ��
|
10
|
+
�� ��
|
11
|
+
�� ��
|
12
|
+
�� ����
|
13
|
+
�� ��
|
14
|
+
�� ����
|
15
|
+
�� ��
|
16
|
+
�� ����
|
17
|
+
�� ��
|
18
|
+
�� ����
|
19
|
+
�� ��
|
20
|
+
�� ����
|
21
|
+
�� ��
|
22
|
+
�� ����
|
23
|
+
�� ��
|
24
|
+
�� ����
|
25
|
+
�� ��
|
26
|
+
�� ����
|
27
|
+
�� ��
|
28
|
+
�� ����
|
29
|
+
�� ��
|
30
|
+
�� ����
|
31
|
+
�� ��
|
32
|
+
�� ����
|
33
|
+
�� ��
|
34
|
+
�� ����
|
35
|
+
�� ��
|
36
|
+
�� ��
|
37
|
+
�� ��
|
38
|
+
�� ��
|
39
|
+
�� ��
|
40
|
+
�� ��
|
41
|
+
�� ��
|
42
|
+
�� ��
|
43
|
+
�� ��
|
44
|
+
�� ��
|
45
|
+
�� ��
|
46
|
+
�� ��
|
47
|
+
�� ��
|
48
|
+
�� �ʎ�
|
49
|
+
�� �ʎ�
|
50
|
+
�� ��
|
51
|
+
�� �ˎ�
|
52
|
+
�� �ˎ�
|
53
|
+
�� ��
|
54
|
+
�� �̎�
|
55
|
+
�� �̎�
|
56
|
+
�� ��
|
57
|
+
�� �͎�
|
58
|
+
�� �͎�
|
59
|
+
�� ��
|
60
|
+
�� �Ύ�
|
61
|
+
�� �Ύ�
|
62
|
+
�� ��
|
63
|
+
�� ��
|
64
|
+
�� ��
|
65
|
+
�� ��
|
66
|
+
�� ��
|
67
|
+
�� ��
|
68
|
+
�� ��
|
69
|
+
�� ��
|
70
|
+
�� ��
|
71
|
+
�� ��
|
72
|
+
�� ��
|
73
|
+
�� ��
|
74
|
+
�� ��
|
75
|
+
�� ��
|
76
|
+
�� ��
|
77
|
+
�� ��
|
78
|
+
�� ��
|
79
|
+
�� ��
|
80
|
+
�� ��
|
81
|
+
�� ����
|
82
|
+
�� ��
|
83
|
+
�� ��
|
84
|
+
�� ��
|
85
|
+
�� ��
|
86
|
+
�� ��
|
87
|
+
�� ��
|
88
|
+
�� ��
|
89
|
+
�� ��
|
@@ -0,0 +1,89 @@
|
|
1
|
+
�@ �
|
2
|
+
�A �
|
3
|
+
�B �
|
4
|
+
�C �
|
5
|
+
�D �
|
6
|
+
�E �
|
7
|
+
�F �
|
8
|
+
�G �
|
9
|
+
�H �
|
10
|
+
�I �
|
11
|
+
�J �
|
12
|
+
�K ��
|
13
|
+
�L �
|
14
|
+
�M ��
|
15
|
+
�N �
|
16
|
+
�O ��
|
17
|
+
�P �
|
18
|
+
�Q ��
|
19
|
+
�R �
|
20
|
+
�S ��
|
21
|
+
�T �
|
22
|
+
�U ��
|
23
|
+
�V �
|
24
|
+
�W ��
|
25
|
+
�X �
|
26
|
+
�Y ��
|
27
|
+
�Z �
|
28
|
+
�[ ��
|
29
|
+
�\ �
|
30
|
+
�] ��
|
31
|
+
�^ �
|
32
|
+
�_ ��
|
33
|
+
�` �
|
34
|
+
�a ��
|
35
|
+
�b �
|
36
|
+
�c �
|
37
|
+
�d ��
|
38
|
+
�e �
|
39
|
+
�f ��
|
40
|
+
�g �
|
41
|
+
�h ��
|
42
|
+
�i �
|
43
|
+
�j �
|
44
|
+
�k �
|
45
|
+
�l �
|
46
|
+
�m �
|
47
|
+
�n �
|
48
|
+
�o ��
|
49
|
+
�p ��
|
50
|
+
�q �
|
51
|
+
�r ��
|
52
|
+
�s ��
|
53
|
+
�t �
|
54
|
+
�u ��
|
55
|
+
�v ��
|
56
|
+
�w �
|
57
|
+
�x ��
|
58
|
+
�y ��
|
59
|
+
�z �
|
60
|
+
�{ ��
|
61
|
+
�| ��
|
62
|
+
�} �
|
63
|
+
�~ �
|
64
|
+
�� �
|
65
|
+
�� �
|
66
|
+
�� �
|
67
|
+
�� �
|
68
|
+
�� �
|
69
|
+
�� �
|
70
|
+
�� �
|
71
|
+
�� �
|
72
|
+
�� �
|
73
|
+
�� �
|
74
|
+
�� �
|
75
|
+
�� �
|
76
|
+
�� �
|
77
|
+
�� �
|
78
|
+
�� �
|
79
|
+
�� �
|
80
|
+
�� �
|
81
|
+
�� ��
|
82
|
+
�[ �
|
83
|
+
�J �
|
84
|
+
�K �
|
85
|
+
�B �
|
86
|
+
�A �
|
87
|
+
�u �
|
88
|
+
�v �
|
89
|
+
�E �
|
@@ -0,0 +1,89 @@
|
|
1
|
+
ァ ァ
|
2
|
+
ア ア
|
3
|
+
ィ ィ
|
4
|
+
イ イ
|
5
|
+
ゥ ゥ
|
6
|
+
ウ ウ
|
7
|
+
ェ ェ
|
8
|
+
エ エ
|
9
|
+
ォ ォ
|
10
|
+
オ オ
|
11
|
+
カ カ
|
12
|
+
ガ ガ
|
13
|
+
キ キ
|
14
|
+
ギ ギ
|
15
|
+
ク ク
|
16
|
+
グ グ
|
17
|
+
ケ ケ
|
18
|
+
ゲ ゲ
|
19
|
+
コ コ
|
20
|
+
ゴ ゴ
|
21
|
+
サ サ
|
22
|
+
ザ ザ
|
23
|
+
シ シ
|
24
|
+
ジ ジ
|
25
|
+
ス ス
|
26
|
+
ズ ズ
|
27
|
+
セ セ
|
28
|
+
ゼ ゼ
|
29
|
+
ソ ソ
|
30
|
+
ゾ ゾ
|
31
|
+
タ タ
|
32
|
+
ダ ダ
|
33
|
+
チ チ
|
34
|
+
ヂ ヂ
|
35
|
+
ッ ッ
|
36
|
+
ツ ツ
|
37
|
+
ヅ ヅ
|
38
|
+
テ テ
|
39
|
+
デ デ
|
40
|
+
ト ト
|
41
|
+
ド ド
|
42
|
+
ナ ナ
|
43
|
+
ニ ニ
|
44
|
+
ヌ ヌ
|
45
|
+
ネ ネ
|
46
|
+
ノ ノ
|
47
|
+
ハ ハ
|
48
|
+
バ バ
|
49
|
+
パ パ
|
50
|
+
ヒ ヒ
|
51
|
+
ビ ビ
|
52
|
+
ピ ピ
|
53
|
+
フ フ
|
54
|
+
ブ ブ
|
55
|
+
プ プ
|
56
|
+
ヘ ヘ
|
57
|
+
ベ ベ
|
58
|
+
ペ ペ
|
59
|
+
ホ ホ
|
60
|
+
ボ ボ
|
61
|
+
ポ ポ
|
62
|
+
マ マ
|
63
|
+
ミ ミ
|
64
|
+
ム ム
|
65
|
+
メ メ
|
66
|
+
モ モ
|
67
|
+
ャ ャ
|
68
|
+
ヤ ヤ
|
69
|
+
ュ ュ
|
70
|
+
ユ ユ
|
71
|
+
ョ ョ
|
72
|
+
ヨ ヨ
|
73
|
+
ラ ラ
|
74
|
+
リ リ
|
75
|
+
ル ル
|
76
|
+
レ レ
|
77
|
+
ロ ロ
|
78
|
+
ワ ワ
|
79
|
+
ヲ ヲ
|
80
|
+
ン ン
|
81
|
+
ヴ ヴ
|
82
|
+
ー ー
|
83
|
+
゛ ゙
|
84
|
+
゜ ゚
|
85
|
+
。 。
|
86
|
+
、 、
|
87
|
+
「 「
|
88
|
+
」 」
|
89
|
+
・ ・
|
data/lib/string_z2h.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
$String_z2h ||= {:a => {}, :h => {}, :h2z => {}, :hd => Hash[*%w(
|
5
|
+
EUC (\x8E[\xDE\xDF])?
|
6
|
+
SJIS ([\xDE\xDF])?
|
7
|
+
UTF8 (\xEF\xBE[\x9E\x9F])?
|
8
|
+
)]}
|
9
|
+
|
10
|
+
|
11
|
+
module StringZ2h
|
12
|
+
require "string_z2h/version"
|
13
|
+
end
|
14
|
+
|
15
|
+
class String
|
16
|
+
# convert 2byte charactor to 1byte charactor
|
17
|
+
# mode
|
18
|
+
# :ascii : convert ascii char to 1byte char and kana char to 2byte char.
|
19
|
+
# :kana : convert ascii char to 2byte char and kana char to 1byte char.
|
20
|
+
# :all : convert ascii char to 1byte char and kana char to 1byte char.
|
21
|
+
def to_han(mode = :ascii)
|
22
|
+
z2h = z2h_h(mode)
|
23
|
+
gsub(/./){ |_| z2h[_] || _ }
|
24
|
+
end
|
25
|
+
|
26
|
+
# convert 1byte charactor to 2byte charactor
|
27
|
+
# mode
|
28
|
+
# :ascii : convert ascii char to 2byte char and kana char to 1byte char.
|
29
|
+
# :kana : convert ascii char to 1byte char and kana char to 2byte char.
|
30
|
+
# :all : convert ascii char to 2byte char and kana char to 2byte char.
|
31
|
+
def to_zen(mode = :ascii)
|
32
|
+
h2z = z2h_h2z(mode)
|
33
|
+
ptn = %r{(.)#{$String_z2h[:hd][$KCODE]}}
|
34
|
+
gsub(ptn){ |_| h2z[_] || ($2.to_s.empty? ? _ : ((h2z[$1] || $1) + (h2z[$2] || $2))) }
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def z2h_a(mode)
|
39
|
+
return z2h_a(:ascii) + z2h_a(:kana) if mode == :all
|
40
|
+
$String_z2h[:a]["#{mode}.#{$KCODE}"] ||= File.open(
|
41
|
+
"#{File.dirname(__FILE__)}/string_z2h/#{mode}.#{$KCODE}", 'rb'
|
42
|
+
){ |_| _.read.split(/[\t\n]/) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def z2h_h(mode)
|
46
|
+
$String_z2h[:h]["#{mode}.#{$KCODE}"] ||= Hash[*(z2h_a(mode))]
|
47
|
+
end
|
48
|
+
|
49
|
+
def z2h_h2z(mode)
|
50
|
+
$String_z2h[:h2z]["#{mode}.#{$KCODE}"] ||= Hash[*(z2h_a(mode).reverse)]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|