Type Function Library utf8.* Return value Number Revision Current Public Release (2018.3326) Keywords utf8, UTF-8, Unicode, string, width
Calculates the width of
s in terms of character positions, taking into account whether characters are
Note that this is an approximation which may be useful, but it's limited to circumstances where a monospace width estimate is appropriate.
The return value of this function depends on usage:
s is a code point, returns the width of that code point.
ambiIsDouble is specified and
true, the ambiguous width character's width is
2; otherwise it's
1. For comparison, the width of
2 while other characters have a width of
defaultWidth is specified, it will be used as the width for unprintable characters.
utf8.width( s [, ambiIsDouble [, defaultWidth]] )
String. The string to examine.
true, the ambiguous width character's width is regarded as
2; otherwise it's regarded as
Number. If specified, this value will be used as the width for unprintable characters.
local utf8 = require( "plugin.utf8" ) local testStr = "♡ 你好，世界 ♡" print( utf8.width( testStr ) ) --> 14 print( utf8.width( testStr, true ) ) --> 16 print( utf8.width( utf8.codepoint( testStr, 5, 7 ), false ) ) --> 2