UnicodeToEbcdic (Unicode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (tags and edits)
m (tags and edits)
Line 10: Line 10:
<tr><th>unicode</th>
<tr><th>unicode</th>
<td>A <var>Unicode</var> string to be translated.</td></tr>
<td>A <var>Unicode</var> string to be translated.</td></tr>
<tr><th>CharacterEncode</th>
<tr><th><var>CharacterEncode</var></th>
<td>The optional (<var>[[Methods#Named parameters|NameRequired]]</var>) <var class="term">CharacterEncode</var> argument is a [[Boolean enumeration]]:<ul><li>If its value is <code>False</code>, the default, an exception is thrown if the input contains any Unicode character not translatable to EBCDIC. <li>If its value is <Code>True</code>, any Unicode character not translatable to EBCDIC is replaced with the hexadecimal character reference of the character, and the ampersand character is replaced with <code>&amp;amp;</code>.  For example, the eight characters <code>&amp;#x201C;</code> replace the Unicode left double-quotation mark (<tt>&#X201C;</tt>). </ul></td></tr>
<td>The optional (<var>[[Methods#Named parameters|NameRequired]]</var>) <var class="term">CharacterEncode</var> argument is a [[Boolean enumeration]]:<ul><li>If its value is <code>False</code>, the default, an exception is thrown if the input contains any Unicode character not translatable to EBCDIC. <li>If its value is <Code>True</code>, any Unicode character not translatable to EBCDIC is replaced with the hexadecimal character reference of the character, and the ampersand character is replaced with <code>&amp;amp;amp;</code>.  For example, the eight characters <code>&amp;amp;#x201C;</code> replace the Unicode left double-quotation mark (<tt>&amp;#X201C;</tt>). </ul></td></tr>
</table>
</table>


Line 30: Line 30:
<ol><li>
<ol><li>
The following example shows multiple calls of <var>UnicodeToEbcdic</var>.
The following example shows multiple calls of <var>UnicodeToEbcdic</var>.
<p class="code">%u Unicode Initial('&amp;#x31;':[[U (String function)|U]])
<p class="code">%u Unicode Initial('&amp;amp;#x31;':[[U (String function)|U]])
print %u:UnicodeToEbcdic
print %u:UnicodeToEbcdic


%u = '1&amp;#x80;2':U
%u = '1&amp;amp;#x80;2':U
print %u:UnicodeToEbcdic(CharacterEncode=True)
print %u:UnicodeToEbcdic(CharacterEncode=True)
print %u:UnicodeToEbcdic
print %u:UnicodeToEbcdic
Line 39: Line 39:
The result of the above fragment is:
The result of the above fragment is:
<p class="output">1
<p class="output">1
1&amp;#x0080;2
1&amp;amp;#x0080;2
CANCELLING REQUEST: MSIR.0751: Class STRING, function
CANCELLING REQUEST: MSIR.0751: Class STRING, function
  UNICODETOEBCDIC: CHARACTER TRANSLATIONEXCEPTION
  UNICODETOEBCDIC: CHARACTER TRANSLATIONEXCEPTION

Revision as of 00:55, 13 April 2011

Translate to Ebcdic (Unicode class)

UnicodeToEbcdic converts a Unicode string to EBCDIC. Optionally, untranslatable characters can be represented with XML style hexadecimal character references.

Syntax

%string = unicode:UnicodeToEbcdic[( [CharacterEncode= boolean])] Throws CharacterTranslationException

Syntax terms

%string A string variable to receive the method object string translated to EBCDIC.
unicode A Unicode string to be translated.
CharacterEncode The optional (NameRequired) CharacterEncode argument is a Boolean enumeration:
  • If its value is False, the default, an exception is thrown if the input contains any Unicode character not translatable to EBCDIC.
  • If its value is True, any Unicode character not translatable to EBCDIC is replaced with the hexadecimal character reference of the character, and the ampersand character is replaced with &amp;amp;. For example, the eight characters &amp;#x201C; replace the Unicode left double-quotation mark (&#X201C;).

Exceptions

This function 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

  • Unless the CharacterEncode argument is used, or you want to Catch a CharacterTranslationException, this function is generally not needed, because a Unicode string is implicitly converted to EBCDIC when used in an EBCDIC context. See the following example.
  • The UnicodeToEbcdic function is available as of Sirius Mods Version 7.3.

Examples

  1. The following example shows multiple calls of UnicodeToEbcdic.

    %u Unicode Initial('&amp;#x31;':U) print %u:UnicodeToEbcdic %u = '1&amp;#x80;2':U print %u:UnicodeToEbcdic(CharacterEncode=True) print %u:UnicodeToEbcdic

    The result of the above fragment is:

    1 1&amp;#x0080;2 CANCELLING REQUEST: MSIR.0751: Class STRING, function UNICODETOEBCDIC: CHARACTER TRANSLATIONEXCEPTION exception: Unicode character U+0080 without valid translation to EBCDIC at byte position 5 ...

    Note: Because of the implicit conversion of Unicode strings (in this case to String), the Print %u:UnicodeToEbcdic statements in the example above could be replaced by Print %u statements and the results would be the same.

See also