1 /*
2 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
7551
7552 /**
7553 * Returns a {@code String} object representing this
7554 * {@code Character}'s value. The result is a string of
7555 * length 1 whose sole component is the primitive
7556 * {@code char} value represented by this
7557 * {@code Character} object.
7558 *
7559 * @return a string representation of this object.
7560 */
7561 public String toString() {
7562 char buf[] = {value};
7563 return String.valueOf(buf);
7564 }
7565
7566 /**
7567 * Returns a {@code String} object representing the
7568 * specified {@code char}. The result is a string of length
7569 * 1 consisting solely of the specified {@code char}.
7570 *
7571 * @param c the {@code char} to be converted
7572 * @return the string representation of the specified {@code char}
7573 * @since 1.4
7574 */
7575 public static String toString(char c) {
7576 return String.valueOf(c);
7577 }
7578
7579 /**
7580 * Determines whether the specified code point is a valid
7581 * <a href="http://www.unicode.org/glossary/#code_point">
7582 * Unicode code point value</a>.
7583 *
7584 * @param codePoint the Unicode code point to be tested
7585 * @return {@code true} if the specified code point value is between
7586 * {@link #MIN_CODE_POINT} and
7587 * {@link #MAX_CODE_POINT} inclusive;
7588 * {@code false} otherwise.
7589 * @since 1.5
7590 */
7591 public static boolean isValidCodePoint(int codePoint) {
7592 // Optimized form of:
7593 // codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
7594 int plane = codePoint >>> 16;
7595 return plane < ((MAX_CODE_POINT + 1) >>> 16);
7596 }
7597
7598 /**
7599 * Determines whether the specified character (Unicode code point)
|
1 /*
2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
7551
7552 /**
7553 * Returns a {@code String} object representing this
7554 * {@code Character}'s value. The result is a string of
7555 * length 1 whose sole component is the primitive
7556 * {@code char} value represented by this
7557 * {@code Character} object.
7558 *
7559 * @return a string representation of this object.
7560 */
7561 public String toString() {
7562 char buf[] = {value};
7563 return String.valueOf(buf);
7564 }
7565
7566 /**
7567 * Returns a {@code String} object representing the
7568 * specified {@code char}. The result is a string of length
7569 * 1 consisting solely of the specified {@code char}.
7570 *
7571 * @apiNote This method cannot handle <a
7572 * href="#supplementary"> supplementary characters</a>. To support
7573 * all Unicode characters, including supplementary characters, use
7574 * the {@link #toString(int)} method.
7575 *
7576 * @param c the {@code char} to be converted
7577 * @return the string representation of the specified {@code char}
7578 * @since 1.4
7579 */
7580 public static String toString(char c) {
7581 return String.valueOf(c);
7582 }
7583
7584 /**
7585 * Returns a {@code String} object representing the
7586 * specified character (Unicode code point). The result is a string of
7587 * length 1 or 2, consisting solely of the specified {@code codePoint}.
7588 *
7589 * @param codePoint the {@code codePoint} to be converted
7590 * @return the string representation of the specified {@code codePoint}
7591 * @exception IllegalArgumentException if the specified
7592 * {@code codePoint} is not a {@linkplain #isValidCodePoint
7593 * valid Unicode code point}.
7594 * @since 11
7595 */
7596 public static String toString(int codePoint) {
7597 return String.valueOfCodePoint(codePoint);
7598 }
7599
7600 /**
7601 * Determines whether the specified code point is a valid
7602 * <a href="http://www.unicode.org/glossary/#code_point">
7603 * Unicode code point value</a>.
7604 *
7605 * @param codePoint the Unicode code point to be tested
7606 * @return {@code true} if the specified code point value is between
7607 * {@link #MIN_CODE_POINT} and
7608 * {@link #MAX_CODE_POINT} inclusive;
7609 * {@code false} otherwise.
7610 * @since 1.5
7611 */
7612 public static boolean isValidCodePoint(int codePoint) {
7613 // Optimized form of:
7614 // codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
7615 int plane = codePoint >>> 16;
7616 return plane < ((MAX_CODE_POINT + 1) >>> 16);
7617 }
7618
7619 /**
7620 * Determines whether the specified character (Unicode code point)
|