Pure Lua implementation of wcwidth function. This function determines the number of column positions required for the character to display. The value passed must be a character code.
local wcwidth = require 'wcwidth'
print( wcwidth( 0 )) -- prints 0
print( wcwidth( 32 )) -- prints 1, ASCII space
print( wcwidth( 0x0410 )) -- prints 1, cyrillic "A"
print( wcwidth( 0x30b3 )) -- prints 2, katakana "コ"
The function either returns 0
(if wc
is a null wide-character code), or
returns the number of column positions to be occupied by the wide-character
code wc
, or returns −1
(if wc does not correspond to a printing
wide-character code)