Utf8.width

From Multi Theft Auto: Wiki
Revision as of 17:31, 15 February 2016 by Necktrox (talk | contribs) (Created page with "__NOTOC__ {{Shared function}} Calculate the width of UTF-8 strings with special/unprintable characters, which require special width treatment. ==Syntax== <syntaxhighlight lang="lua">int utf8...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Calculate the width of UTF-8 strings with special/unprintable characters, which require special width treatment.

Syntax

int utf8.width ( string|int input [, bool ambi_is_double = false, int default_width = 0 ] )

Required Arguments

  • input: A string character sequence OR a code point number

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • ambi_is_double: A boolean, if set to true, ambiguous character's width is 2 (see example below).
  • default_width: A number, if given, is used as width for unprintable characters.

Returns

Returns the number width of the input string or code point number.

Example

Click to collapse [-]
Server

This example shows the difference when ambi_is_double is set to false or true.

local input = "днём"
local disabled = utf8.width( input, false )
local enabled = utf8.width( input, true )

print( disabled, enabled ) -- 4, 8

See Also