Method: Unicode::Name.label

Defined in:
lib/unicode/name.rb

.label(char) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/unicode/name.rb', line 44

def self.label(char)
  codepoint = char.unpack("U")[0]
  codepoint_pretty = "%.4X" % codepoint
  require_relative "name/index" unless defined? ::Unicode::Name::INDEX
  require "unicode/types" unless defined? ::Unicode::Types
  case Unicode::Types.type(char)
  when "Graphic", "Format"
    nil
  when "Control"
    "<control-#{codepoint_pretty}>"
  when "Private-use"
    "<private-use-#{codepoint_pretty}>"
  when "Surrogate"
    "<surrogate-#{codepoint_pretty}>"
  when "Noncharacter"
    "<noncharacter-#{codepoint_pretty}>"
  when "Reserved"
    "<reserved-#{codepoint_pretty}>"
  end
end