module Wcswidth

Constants

MAX_WIDTH
VERSION
WCHAR_SIZE
WCHAR_TEMPLATE

Public Class Methods

of(string, max_width = MAX_WIDTH) click to toggle source
# File lib/wcswidth.rb, line 6
def self.of(string, max_width = MAX_WIDTH)
  LibC.wcswidth(
    [
      *string.to_s.  # ensure we are working with a string
      tr("\0", "").  # remove 0 bytes (length is 0)
      codepoints,    # convert to integer character representations
      0              # append 0 byte
    ].pack(WCHAR_TEMPLATE), # generate wchar_t byte representation
    max_width        # pass max column width
  )
end