Module: JapaneseAddressParser::Zen2han
- Defined in:
- lib/japanese_address_parser/zen2han.rb,
sig/zen2han.rbs
Overview
全角の英数字(A-Z・a-z・0-9)を半角へ変換する。
Class Method Summary collapse
-
.call(str) ⇒ Object
JS: str.replace(/[A-Za-z0-9]/g, (s) => String.fromCharCode(s.charCodeAt(0) - 0xfee0)) 全角英数字のコードポイントは半角より 0xFEE0 大きいので、その差を引いて半角へ落とす。 文字クラスは上流のリテラル範囲をそのまま移植する。.
Instance Method Summary collapse
Class Method Details
.call(str) ⇒ Object
JS:
str.replace(/[A-Za-z0-9]/g, (s) => String.fromCharCode(s.charCodeAt(0) - 0xfee0))
全角英数字のコードポイントは半角より 0xFEE0 大きいので、その差を引いて半角へ落とす。 文字クラスは上流のリテラル範囲をそのまま移植する。
15 16 17 |
# File 'lib/japanese_address_parser/zen2han.rb', line 15 def call(str) str.gsub(/[A-Za-z0-9]/) { |s| (s.ord - 0xFEE0).chr(::Encoding::UTF_8) } end |
Instance Method Details
#self?.call ⇒ String
4 |
# File 'sig/zen2han.rbs', line 4
def self?.call: (String str) -> String
|