Utf8.widthindex
From Multi Theft Auto: Wiki
Returns the location, offset and width of the character at the given location in the UTF-8 string.
Syntax
int, int, int utf8.width ( 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 |