class String

def to_full_characters(alpha: true, number: true, symbol: false)

Returns:
  • (String) -

Parameters:
  • symbol (TrueClass, FalseClass) --
  • number (TrueClass, FalseClass) --
  • alpha (TrueClass, FalseClass) --

Other tags:
    Note: - 반각 문자 -> 전각 문자
def to_full_characters(alpha: true, number: true, symbol: false)
  result = String.new
  return result if self.blank?
  (0...self.size).each do |i|
    half_ord = self[i].ord
    full_ord = half_ord + 0xfee0
    char_ord = case half_ord
               when 0x20 then 0x3000
               when ('0'.ord)..('9'.ord) then number ? full_ord : half_ord
               when ('A'.ord)..('Z'.ord) then alpha ? full_ord : half_ord
               when ('a'.ord)..('z'.ord) then alpha ? full_ord : half_ord
               when ('!'.ord)..('~'.ord) then symbol ? full_ord : half_ord
               else half_ord
               end
    result << char_ord.chr('UTF-8')
  end
  result
end