module Unicode::DisplayWidth
Constants
- DATA_DIRECTORY
- INDEX
- INDEX_FILENAME
- NO_STRING_EXT
- VERSION
Public Class Methods
of(string, ambiguous = 1, overwrite = {})
click to toggle source
# File lib/unicode/display_width.rb, line 5 def self.of(string, ambiguous = 1, overwrite = {}) require_relative 'display_width/index' unless defined? ::Unicode::DisplayWidth::INDEX res = string.unpack('U*').inject(0){ |total_width, codepoint| total_width + ( overwrite[codepoint] || case width = INDEX[codepoint] when Integer width when :F, :W 2 when :A ambiguous else # including :N, :Na, :H 1 end ) } res < 0 ? 0 : res end