src/java.base/share/classes/java/lang/String.java
changeset 49129 fb9f590b9eee
parent 49122 fc16b5f193c7
child 49211 948ece16567b
equal deleted inserted replaced
49128:97288886180c 49129:fb9f590b9eee
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  3155         if (begin < 0 || begin > end || end > length) {
  3155         if (begin < 0 || begin > end || end > length) {
  3156             throw new StringIndexOutOfBoundsException(
  3156             throw new StringIndexOutOfBoundsException(
  3157                 "begin " + begin + ", end " + end + ", length " + length);
  3157                 "begin " + begin + ", end " + end + ", length " + length);
  3158         }
  3158         }
  3159     }
  3159     }
       
  3160 
       
  3161     /**
       
  3162      * Returns the string representation of the {@code codePoint}
       
  3163      * argument.
       
  3164      *
       
  3165      * @param   codePoint a {@code codePoint}.
       
  3166      * @return  a string of length {@code 1} or {@code 2} containing
       
  3167      *          as its single character the argument {@code codePoint}.
       
  3168      * @throws IllegalArgumentException if the specified
       
  3169      *          {@code codePoint} is not a {@linkplain Character#isValidCodePoint
       
  3170      *          valid Unicode code point}.
       
  3171      */
       
  3172     static String valueOfCodePoint(int codePoint) {
       
  3173         if (COMPACT_STRINGS && StringLatin1.canEncode(codePoint)) {
       
  3174             return new String(StringLatin1.toBytes((char)codePoint), LATIN1);
       
  3175         } else if (Character.isBmpCodePoint(codePoint)) {
       
  3176             return new String(StringUTF16.toBytes((char)codePoint), UTF16);
       
  3177         } else if (Character.isSupplementaryCodePoint(codePoint)) {
       
  3178             return new String(StringUTF16.toBytesSupplementary(codePoint), UTF16);
       
  3179         }
       
  3180 
       
  3181         throw new IllegalArgumentException("Not a valid Unicode code point");
       
  3182     }
  3160 }
  3183 }