< prev index next >
src/java.base/share/classes/sun/text/normalizer/UTF16.java
Print this page
*** 36,65 ****
package sun.text.normalizer;
/**
* <p>Standalone utility class providing UTF16 character conversions and
! * indexing conversions.</p>
* <p>Code that uses strings alone rarely need modification.
* By design, UTF-16 does not allow overlap, so searching for strings is a safe
* operation. Similarly, concatenation is always safe. Substringing is safe if
* the start and end are both on UTF-32 boundaries. In normal code, the values
* for start and end are on those boundaries, since they arose from operations
* like searching. If not, the nearest UTF-32 boundaries can be determined
! * using <code>bounds()</code>.</p>
* <strong>Examples:</strong>
* <p>The following examples illustrate use of some of these methods.
! * <pre>
* // iteration forwards: Original
! * for (int i = 0; i < s.length(); ++i) {
* char ch = s.charAt(i);
* doSomethingWith(ch);
* }
*
* // iteration forwards: Changes for UTF-32
* int ch;
! * for (int i = 0; i < s.length(); i+=UTF16.getCharCount(ch)) {
* ch = UTF16.charAt(s,i);
* doSomethingWith(ch);
* }
*
* // iteration backwards: Original
--- 36,65 ----
package sun.text.normalizer;
/**
* <p>Standalone utility class providing UTF16 character conversions and
! * indexing conversions.
* <p>Code that uses strings alone rarely need modification.
* By design, UTF-16 does not allow overlap, so searching for strings is a safe
* operation. Similarly, concatenation is always safe. Substringing is safe if
* the start and end are both on UTF-32 boundaries. In normal code, the values
* for start and end are on those boundaries, since they arose from operations
* like searching. If not, the nearest UTF-32 boundaries can be determined
! * using <code>bounds()</code>.
* <strong>Examples:</strong>
* <p>The following examples illustrate use of some of these methods.
! * <pre>{@code
* // iteration forwards: Original
! * for (int i = 0; i < s.length(); ++i) {
* char ch = s.charAt(i);
* doSomethingWith(ch);
* }
*
* // iteration forwards: Changes for UTF-32
* int ch;
! * for (int i = 0; i < s.length(); i+=UTF16.getCharCount(ch)) {
* ch = UTF16.charAt(s,i);
* doSomethingWith(ch);
* }
*
* // iteration backwards: Original
*** 72,82 ****
* int ch;
* for (int i = s.length() -1; i > 0; i-=UTF16.getCharCount(ch)) {
* ch = UTF16.charAt(s,i);
* doSomethingWith(ch);
* }
! * </pre>
* <strong>Notes:</strong>
* <ul>
* <li>
* <strong>Naming:</strong> For clarity, High and Low surrogates are called
* <code>Lead</code> and <code>Trail</code> in the API, which gives a better
--- 72,82 ----
* int ch;
* for (int i = s.length() -1; i > 0; i-=UTF16.getCharCount(ch)) {
* ch = UTF16.charAt(s,i);
* doSomethingWith(ch);
* }
! * }</pre>
* <strong>Notes:</strong>
* <ul>
* <li>
* <strong>Naming:</strong> For clarity, High and Low surrogates are called
* <code>Lead</code> and <code>Trail</code> in the API, which gives a better
*** 513,528 ****
// private methods ------------------------------------------------------
/**
* <p>Converts argument code point and returns a String object representing
! * the code point's value in UTF16 format.</p>
* <p>This method does not check for the validity of the codepoint, the
* results are not guaranteed if a invalid codepoint is passed as
! * argument.</p>
* <p>The result is a string whose length is 1 for non-supplementary code
! * points, 2 otherwise.</p>
* @param ch code point
* @return string representation of the code point
*/
private static String toString(int ch)
{
--- 513,528 ----
// private methods ------------------------------------------------------
/**
* <p>Converts argument code point and returns a String object representing
! * the code point's value in UTF16 format.
* <p>This method does not check for the validity of the codepoint, the
* results are not guaranteed if a invalid codepoint is passed as
! * argument.
* <p>The result is a string whose length is 1 for non-supplementary code
! * points, 2 otherwise.
* @param ch code point
* @return string representation of the code point
*/
private static String toString(int ch)
{
< prev index next >