Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/unicode/display_width.rb

Overview

# # core ext

Instance Method Summary collapse

Instance Method Details

#display_width(ambiguous = 1) ⇒ Object Also known as: display_size, display_length



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/unicode/display_width.rb', line 60

def display_width(ambiguous = 1)
  unpack('U*').inject(0){ |a,c|
    width = case Unicode::DisplayWidth.codepoint(c).to_s
            when *%w[F W]
              2
            when *%w[N Na H]
              1
            when *%w[A]
              ambiguous
            else
              1
            end
    a + width
  }
end