UnicodeUrlEncode and UnicodeFormUrlEncode (Unicode functions)

From m204wiki
Jump to navigation Jump to search

URL encode unicode characters (Unicode class)

[Introduced in Sirius Mods 7.9]


UnicodeUrlEncode and UnicodeFormUrlEncode URL encode or percent-encode a Unicode string.

Syntax

%string = unicode:UnicodeUrlEncode

%string = unicode:UnicodeFormUrlEncode

Syntax terms

%stringThe UTF-8 encoded string that results from URL or percent encoding unicode.
unicode The Unicode method object that is to be URL encoded.

Usage notes

  • If an EBCDIC version of the UTF-8 encoded unicode string is needed, the UTF-8 encoded string should be converted back to unicode using Utf8ToUnicode and then assigned to a string variable using either implicit Unicode to EBCDIC translation or doing it explicitly with UnicodeToEbcdic. The conversion back to EBCDIC should require no character entity encoding since URL encoding only uses the most common ASCII characters. This process is shown in the following example.
  • The difference between UnicodeFormUrlEncode and UnicodeUrlEncode is that UnicodeFormUrlDecode converts spaces to pluses (+) while UnicodeUrlEncode percent encodes spaces as %20. Typically, form URL encoding is only used in HTML form posts when the form is posted using the x-www-form-urlencoded content type.
  • URL encoding is mostly used in web applications or for encoding a URI, possibly in an XML namespace declaration.

Examples

The following example URL encodes a Unicode string and converts it to EBCDIC:

begin %ebcdic is longstring %unicode is unicode %unicode = 'I like apple π. and eat it 4 × a day.':u %ebcdic = %unicode:unicodeUrlEncode:utf8ToUnicode printText {~} = {%ebcdic} end

The example output is:

%ebcdic = I%20like%20apple%20%CF%80.%20and%20eat%20it%204%20%C3%97%20a%20day.

See also