ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaha_5.4.0.1/literal.htm

73 lines
4.9 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="concept" />
<meta name="DC.Title" content="Literal strings in native methods" />
<meta name="abstract" content="It is easier to encode literal strings in UTF-8 if the string is composed of characters with a 7-bit American Standard Code for Information Interchange (ASCII) representation." />
<meta name="description" content="It is easier to encode literal strings in UTF-8 if the string is composed of characters with a 7-bit American Standard Code for Information Interchange (ASCII) representation." />
<meta name="DC.Relation" scheme="URI" content="strings.htm" />
<meta name="DC.Relation" scheme="URI" content="dynamic.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="literal" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Literal strings in native methods</title>
</head>
<body id="literal"><a name="literal"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Literal strings in native methods</h1>
<div><p>It is easier to encode literal strings in UTF-8 if the string is
composed of characters with a 7-bit American Standard Code for Information
Interchange (ASCII) representation.</p>
<p>If the string can be represented in ASCII, as most are, then the string
can be bracketed by 'pragma' statements that change the current codepage of
the compiler. Then, the compiler stores the string internally in the UTF-8
form that is required by the JNI. If the string cannot be represented in ASCII,
it is easier to treat the original extended binary-coded decimal interchange
code (EBCDIC) string as a dynamic string, and process it using iconv() before
passing it to the JNI. For more information on dynamic strings, see <a href="dynamic.htm">dynamic strings</a>.</p>
<p>For example, to find the class named <samp class="codeph">java/lang/String</samp>,
the code looks like this:</p>
<pre> #pragma convert(819)
myClass = (*env)-&gt;FindClass(env,"java/lang/String");
#pragma convert(0)</pre>
<p>The first pragma, with the number 819, informs the compiler to store all
subsequent double-quoted strings (literal strings) in ASCII. The second pragma,
with the number 0, tells the compiler to revert to the default code page of
the compiler for double-quoted strings, which is usually the EBCDIC code page
37. So, by bracketing this call with these pragmas, we satisfy the JNI requirement
that string parameters are encoded in UTF-8.</p>
<p><strong>Caution:</strong> Be careful with text substitutions. For example, if your
code looks like this:</p>
<pre> #pragma convert(819)
#define MyString "java/lang/String"
#pragma convert(0)
myClass = (*env)-&gt;FindClass(env,MyString);</pre>
<p>Then, the resulting string is EBCDIC, because the value of MyString is
substituted into the FindClass call during compilation. At the time of this
substitution, the pragma, number 819, is not in effect. Thus, literal strings
are not stored in ASCII. </p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="strings.htm" title="Many Java Native Interface (JNI) functions accept C language-style strings as parameters. For example, the FindClass() JNI function accepts a string parameter that specifies the fully-qualified name of a classfile. If the classfile is found, it is loaded by FindClass, and a reference to it is returned to the caller of FindClass.">Strings in native methods</a></div>
</div>
<div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="dynamic.htm" title="To manipulate string variables that are computed at run time, it may be necessary to convert strings to and from extended binary-coded decimal interchange (EBCDIC), Unicode, and UTF-8.">Convert dynamic strings to and from EBCDIC, Unicode, and UTF-8</a></div>
</div>
</div>
</body>
</html>