Utf16ToUnicode (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
Line 14: Line 14:


<tr><th><var>AllowUntranslatable</var></th>
<tr><th><var>AllowUntranslatable</var></th>
<td>This argument is indicates whether this function will store values into the target unicode string that cannot be translated to EBCDIC. This value defaults to <var>True</var> which means that such values would be allowed. If this argument is set to <var>False</var> a unicode value not translatable to EBCDIC would produce a [[CharacterTranslationException class|CharacterTranslationException exception]]. Unless there is a compelling reason to do otherwise it is best to use the default value of <var>True</var>.</p></td></tr>
<td>This argument is indicates whether this function will store values into the target unicode string that cannot be translated to EBCDIC. This value defaults to <var>True</var> which means that such values would be allowed. If this argument is set to <var>False</var> a unicode value not translatable to EBCDIC would produce a [[CharacterTranslationException class|CharacterTranslationException exception]]. Unless there is a compelling reason to do otherwise it is best to use the default value of <var>True</var>.</td></tr>


<tr><th><var>BOM</var></th>
<tr><th><var>BOM</var></th>

Revision as of 17:48, 19 March 2015

Convert a UTF-16 Longstring bytestream to Unicode (String class)

The Utf16ToUnicode intrinsic function converts a UTF-16 Longstring byte stream to Unicode.

Syntax

%unicode = string:Utf16ToUnicode[( [AllowUntranslatable= boolean], - [Bom= utf16BOM])] Throws CharacterTranslationException

Syntax terms

%unicode A Unicode string variable to receive the method object string translated to Unicode.
string A string that is presumed to contain a UTF-16 byte stream.
AllowUntranslatable This argument is indicates whether this function will store values into the target unicode string that cannot be translated to EBCDIC. This value defaults to True which means that such values would be allowed. If this argument is set to False a unicode value not translatable to EBCDIC would produce a CharacterTranslationException exception. Unless there is a compelling reason to do otherwise it is best to use the default value of True.
BOM This Byte Order Mark argument is usable only by Rocket Software. Contact Rocket Software if you think this argument may be of value to you.

BOM is a name required parameter with a value that is a Utf16Bom enumeration.

Exceptions

Utf16ToUnicode can throw the following exception:

CharacterTranslationException
If the method encounters a translation problem, properties of the exception object may indicate the location and type of problem.

Usage notes

  • The input UTF-16 stream may contain a Byte Order Mark (U+FEFF).
    • If one is present, that controls the conversion from UTF-16 to Unicode.
    • If a Byte Order Mark is not present, the input stream is considered to be a Big Endian stream, that is, it is the same as if the stream were preceded by the two bytes X'FE' and X'FF', in that order.
  • The Utf16ToUnicode function is available as of Sirius Mods Version 7.3.

Examples

In the following fragment, Utf16ToUnicode converts a hexadecimal input to a single Unicode character:

%u unicode %u = '0032':X:Utf16ToUnicode print %u

The result is:

2

See also