Utf8.escape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(converted format list to table)
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
{{Shared function}}
{{Shared function}}


Escapes a string to a UTF-8 format string. It supports several escape formats:
Escapes a string to a UTF-8 format string. It supports several escape formats, see the formatting table.
{|  class="prettytable" style="width:30%;"
 
==Syntax==
<syntaxhighlight lang="lua">string utf8.escape ( string input )</syntaxhighlight>
 
===Required Arguments===
*'''input:''' A string character sequence
 
===Returns===
Returns a ''string'' containing the escaped UTF-8 characters from the original string.
 
===Formatting===
{|  class="prettytable" style="width:35%;text-align:left;"
|-
|-
! Format || Description
! Format || Description
|-
|-
| '''%ddd''' || where ddd is a decimal number with variable length
| '''%ddd''' || ddd is a decimal number with variable length
|-
|-
| '''%{ddd}''' || same as above, but enclosed in brackets
| '''%{ddd}''' || same as above, but enclosed in brackets
Line 19: Line 30:
| '''%x{hhh}''' || same as above, but enclosed in brackets
| '''%x{hhh}''' || same as above, but enclosed in brackets
|-
|-
| '''%?''' || where '?' stands for any other character to be escaped
| '''%?''' || '?' stands for any other character to be escaped
|}
|}
==Syntax==
<syntaxhighlight lang="lua">string utf8.escape ( string input )</syntaxhighlight>
===Required Arguments===
*'''input:''' A string character sequence
===Returns===
Returns a ''string'' containing the escaped UTF-8 characters from the original string.


==Example==
==Example==

Latest revision as of 18:34, 15 February 2016

Escapes a string to a UTF-8 format string. It supports several escape formats, see the formatting table.

Syntax

string utf8.escape ( string input )

Required Arguments

  • input: A string character sequence

Returns

Returns a string containing the escaped UTF-8 characters from the original string.

Formatting

Format Description
%ddd ddd is a decimal number with variable length
%{ddd} same as above, but enclosed in brackets
%uddd same as %ddd, 'u' stands for unicode
%u{ddd} same as above, but enclosed in brackets
%xhhh hexadigit version of %ddd
%x{hhh} same as above, but enclosed in brackets
%? '?' stands for any other character to be escaped

Example

Click to collapse [-]
Server

This example escapes two byte-string literals to UTF-8 format by using the utf8.escape function.

local output = utf8.escape( "%123 %u123 %{123} %u{123} %xABC %x{ABC}" )
print( output ) -- { { { { ઼ ઼

local output = utf8.escape( "%%123 %? %d %%u" )
print( output ) -- %123 ? d %u

See Also

Shared