Utf8.width: Difference between revisions
Jump to navigation
Jump to search
(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...") |
m (tweaks) |
||
Line 2: | Line 2: | ||
{{Shared function}} | {{Shared function}} | ||
Calculates the width of UTF-8 strings with special/unprintable characters, which require special width treatment. | |||
==Syntax== | ==Syntax== | ||
Line 8: | Line 8: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''input:''' A string character sequence OR a | *'''input:''' A string character sequence OR a codepoint integer | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''ambi_is_double:''' A boolean, if set to ''true'', ambiguous character's width is 2 (see example below). | *'''ambi_is_double:''' A boolean, if set to ''true'', ambiguous character's width is 2 (see example below). | ||
*'''default_width:''' | *'''default_width:''' An integer, if given, is used as width for unprintable characters. | ||
===Returns=== | ===Returns=== | ||
Returns the '' | Returns the ''integer'' width of the input string OR the width of the codepoint integer. | ||
==Example== | ==Example== |
Latest revision as of 18:50, 15 February 2016
Calculates 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 codepoint integer
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: An integer, if given, is used as width for unprintable characters.
Returns
Returns the integer width of the input string OR the width of the codepoint integer.
Example
Click to collapse [-]
ServerThis 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
Shared
- utf8.byte
- utf8.char
- utf8.charpos
- utf8.escape
- utf8.find
- utf8.fold
- utf8.gmatch
- utf8.gsub
- utf8.insert
- utf8.len
- utf8.lower
- utf8.match
- utf8.ncasecmp
- utf8.next
- utf8.remove
- utf8.reverse
- utf8.sub
- utf8.title
- utf8.upper
- utf8.width
- utf8.widthindex