Utf8.widthindex: Difference between revisions
Jump to navigation
Jump to search
m (tweaks) |
m (→Syntax: function is withindex) |
||
Line 5: | Line 5: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">int, int, int utf8. | <syntaxhighlight lang="lua">int, int, int utf8.widthindex ( string input, int location [, bool ambi_is_double = false, int default_width = 0 ] )</syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== |
Latest revision as of 14:27, 17 February 2021
Returns the location, offset and width of the character at the given location in the UTF-8 string.
Syntax
int, int, int utf8.widthindex ( string input, int location [, bool ambi_is_double = false, int default_width = 0 ] )
Required Arguments
- input: A string character sequence
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).
- default_width: An integer, if given, is used as width for unprintable characters.
Returns
Returns the given location, the offset in UTF-8 encoding (if cursor is in the middle of the wide char - offset will be 2) and the width of the character, otherwise only the location as integer will be returned.
Example
Click to collapse [-]
ServerThis example
local input = "днём" local raw_width = utf8.width( input, true ) for location = 1, raw_width do print( utf8.widthindex( input, location, true ) ) end
Output (enhanced, not raw):
Character | Location | Offset | Width |
---|---|---|---|
д | 1 | 1 | 2 |
д | 1 | 2 | 2 |
н | 2 | 1 | 2 |
н | 2 | 2 | 2 |
ё | 3 | 1 | 2 |
ё | 3 | 2 | 2 |
м | 4 | 1 | 2 |
м | 4 | 2 | 2 |
See Also
- 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