Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_z2h.rb
Instance Method Summary collapse
-
#to_han(mode = :ascii) ⇒ Object
convert 2byte charactor to 1byte charactor mode :ascii : convert ascii char to 1byte char and kana char to 2byte char.
-
#to_zen(mode = :ascii) ⇒ Object
convert 1byte charactor to 2byte charactor mode :ascii : convert ascii char to 2byte char and kana char to 1byte char.
Instance Method Details
#to_han(mode = :ascii) ⇒ Object
convert 2byte charactor to 1byte charactor mode
:ascii : convert ascii char to 1byte char and kana char to 2byte char.
:kana : convert ascii char to 2byte char and kana char to 1byte char.
:all : convert ascii char to 1byte char and kana char to 1byte char.
21 22 23 24 |
# File 'lib/string_z2h.rb', line 21 def to_han(mode = :ascii) z2h = z2h_h(mode) gsub(/./){ |_| z2h[_] || _ } end |
#to_zen(mode = :ascii) ⇒ Object
convert 1byte charactor to 2byte charactor mode
:ascii : convert ascii char to 2byte char and kana char to 1byte char.
:kana : convert ascii char to 1byte char and kana char to 2byte char.
:all : convert ascii char to 2byte char and kana char to 2byte char.
31 32 33 34 35 |
# File 'lib/string_z2h.rb', line 31 def to_zen(mode = :ascii) h2z = z2h_h2z(mode) ptn = %r{(.)#{$String_z2h[:hd][$KCODE]}} gsub(ptn){ |_| h2z[_] || ($2.to_s.empty? ? _ : ((h2z[$1] || $1) + (h2z[$2] || $2))) } end |