Utf8ToUnicode (String function): Difference between revisions
m (→Syntax terms: minor wordsmithing) |
|||
Line 8: | Line 8: | ||
<tr><th>%unicode</th> | <tr><th>%unicode</th> | ||
<td>A Unicode string variable to receive the method object <var class="term">string</var> translated to <var>Unicode</var>.</td></tr> | <td>A Unicode string variable to receive the method object <var class="term">string</var> translated to <var>Unicode</var>.</td></tr> | ||
<tr><th>string</th> | <tr><th>string</th> | ||
<td>The method object <var class="term">string</var> that is presumed to contain a UTF-8 byte stream.</td></tr> | <td>The method object <var class="term">string</var> that is presumed to contain a UTF-8 byte stream.</td></tr> | ||
<tr><th><var>AllowUntranslatable</var></th> | <tr><th><var>AllowUntranslatable</var></th> | ||
<td>This argument indicates whether this function will store values into the target Unicode string | <td>This argument indicates whether this function will store values into the target Unicode string if they 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 produces a [[CharacterTranslationException class|CharacterTranslationException exception]]. | ||
<p> | |||
Unless there is a compelling reason to do otherwise, it is best to use the default value of <var>True</var>.</p></td></tr> | |||
</table> | </table> | ||
Revision as of 22:41, 8 April 2016
Convert a UTF-8 Longstring bytestream to Unicode (String class)
The Utf8ToUnicode intrinsic function converts a UTF-8 string to Unicode.
Syntax
%unicode = string:Utf8ToUnicode[( [AllowUntranslatable= boolean])] Throws CharacterTranslationException
Syntax terms
%unicode | A Unicode string variable to receive the method object string translated to Unicode. |
---|---|
string | The method object string that is presumed to contain a UTF-8 byte stream. |
AllowUntranslatable | This argument indicates whether this function will store values into the target Unicode string if they 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 produces a CharacterTranslationException exception.
Unless there is a compelling reason to do otherwise, it is best to use the default value of True. |
Exceptions
Utf8ToUnicode 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
- Utf8ToUnicode is available as of Sirius Mods Version 7.3.
Examples
In the following fragment, Utf8ToUnicode converts a hexadecimal input to a single Unicode character. In case the Unicode character translates to an EBCDIC character that cannot be displayed, the CharacterEncode option of UnicodeToEbcdic causes the output of a hexadecimal character reference.
%u unicode %u = 'E284A2':X:Utf8ToUnicode print %u:unicodeToEbcdic(CharacterEncode=true)
The result of the above fragment is the character reference for the trademark character:
™
See also
- Utf8 and Utf16 has more information about UTF-8 conversions.
- UnicodeToUtf8 converts a Unicode string to a UTF-8 Longstring byte stream.
- Utf16ToUnicode converts a UTF-16 byte stream to Unicode.