1 /*
2 * Copyright (c) 1994, 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
3091 if (offset < 0 || count < 0 || offset > length - count) {
3092 throw new StringIndexOutOfBoundsException(
3093 "offset " + offset + ", count " + count + ", length " + length);
3094 }
3095 }
3096
3097 /*
3098 * Check {@code begin}, {@code end} against {@code 0} and {@code length}
3099 * bounds.
3100 *
3101 * @throws StringIndexOutOfBoundsException
3102 * If {@code begin} is negative, {@code begin} is greater than
3103 * {@code end}, or {@code end} is greater than {@code length}.
3104 */
3105 static void checkBoundsBeginEnd(int begin, int end, int length) {
3106 if (begin < 0 || begin > end || end > length) {
3107 throw new StringIndexOutOfBoundsException(
3108 "begin " + begin + ", end " + end + ", length " + length);
3109 }
3110 }
3111 }
|
1 /*
2 * Copyright (c) 1994, 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
3091 if (offset < 0 || count < 0 || offset > length - count) {
3092 throw new StringIndexOutOfBoundsException(
3093 "offset " + offset + ", count " + count + ", length " + length);
3094 }
3095 }
3096
3097 /*
3098 * Check {@code begin}, {@code end} against {@code 0} and {@code length}
3099 * bounds.
3100 *
3101 * @throws StringIndexOutOfBoundsException
3102 * If {@code begin} is negative, {@code begin} is greater than
3103 * {@code end}, or {@code end} is greater than {@code length}.
3104 */
3105 static void checkBoundsBeginEnd(int begin, int end, int length) {
3106 if (begin < 0 || begin > end || end > length) {
3107 throw new StringIndexOutOfBoundsException(
3108 "begin " + begin + ", end " + end + ", length " + length);
3109 }
3110 }
3111
3112 /**
3113 * Returns the string representation of the {@code codePoint}
3114 * argument.
3115 *
3116 * @param codepoint a {@code codePoint}.
3117 * @return a string of length {@code 1} or {@code 2} containing
3118 * as its single character the argument {@code codePoint}.
3119 * @throws IllegalArgumentException if the specified
3120 * {@code codePoint} is not a {@linkplain Character#isValidCodePoint
3121 * valid Unicode code point}.
3122 */
3123 static String valueOfCodePoint(int cp) {
3124 if (COMPACT_STRINGS && StringLatin1.canEncode(cp)) {
3125 return new String(StringLatin1.toBytes((char)cp), LATIN1);
3126 } else if (Character.isValidCodePoint(cp)) {
3127 return new String(StringUTF16.toBytes(cp), UTF16);
3128 } else {
3129 throw new IllegalArgumentException();
3130 }
3131 }
3132 }
|