emul/src/main/java/java/lang/String.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 16 Oct 2012 11:55:56 +0200
changeset 104 1376481f15e7
parent 93 a236a9f137ac
child 179 469199c2994a
permissions -rw-r--r--
Concatenation of strings works
     1 /*
     2  * Copyright (c) 1994, 2010, 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
    23  * questions.
    24  */
    25 
    26 package java.lang;
    27 
    28 import org.apidesign.bck2brwsr.core.ExtraJavaScript;
    29 import java.util.Comparator;
    30 
    31 /**
    32  * The <code>String</code> class represents character strings. All
    33  * string literals in Java programs, such as <code>"abc"</code>, are
    34  * implemented as instances of this class.
    35  * <p>
    36  * Strings are constant; their values cannot be changed after they
    37  * are created. String buffers support mutable strings.
    38  * Because String objects are immutable they can be shared. For example:
    39  * <p><blockquote><pre>
    40  *     String str = "abc";
    41  * </pre></blockquote><p>
    42  * is equivalent to:
    43  * <p><blockquote><pre>
    44  *     char data[] = {'a', 'b', 'c'};
    45  *     String str = new String(data);
    46  * </pre></blockquote><p>
    47  * Here are some more examples of how strings can be used:
    48  * <p><blockquote><pre>
    49  *     System.out.println("abc");
    50  *     String cde = "cde";
    51  *     System.out.println("abc" + cde);
    52  *     String c = "abc".substring(2,3);
    53  *     String d = cde.substring(1, 2);
    54  * </pre></blockquote>
    55  * <p>
    56  * The class <code>String</code> includes methods for examining
    57  * individual characters of the sequence, for comparing strings, for
    58  * searching strings, for extracting substrings, and for creating a
    59  * copy of a string with all characters translated to uppercase or to
    60  * lowercase. Case mapping is based on the Unicode Standard version
    61  * specified by the {@link java.lang.Character Character} class.
    62  * <p>
    63  * The Java language provides special support for the string
    64  * concatenation operator (&nbsp;+&nbsp;), and for conversion of
    65  * other objects to strings. String concatenation is implemented
    66  * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
    67  * class and its <code>append</code> method.
    68  * String conversions are implemented through the method
    69  * <code>toString</code>, defined by <code>Object</code> and
    70  * inherited by all classes in Java. For additional information on
    71  * string concatenation and conversion, see Gosling, Joy, and Steele,
    72  * <i>The Java Language Specification</i>.
    73  *
    74  * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
    75  * or method in this class will cause a {@link NullPointerException} to be
    76  * thrown.
    77  *
    78  * <p>A <code>String</code> represents a string in the UTF-16 format
    79  * in which <em>supplementary characters</em> are represented by <em>surrogate
    80  * pairs</em> (see the section <a href="Character.html#unicode">Unicode
    81  * Character Representations</a> in the <code>Character</code> class for
    82  * more information).
    83  * Index values refer to <code>char</code> code units, so a supplementary
    84  * character uses two positions in a <code>String</code>.
    85  * <p>The <code>String</code> class provides methods for dealing with
    86  * Unicode code points (i.e., characters), in addition to those for
    87  * dealing with Unicode code units (i.e., <code>char</code> values).
    88  *
    89  * @author  Lee Boynton
    90  * @author  Arthur van Hoff
    91  * @author  Martin Buchholz
    92  * @author  Ulf Zibis
    93  * @see     java.lang.Object#toString()
    94  * @see     java.lang.StringBuffer
    95  * @see     java.lang.StringBuilder
    96  * @see     java.nio.charset.Charset
    97  * @since   JDK1.0
    98  */
    99 
   100 @ExtraJavaScript(
   101     resource="/org/apidesign/vm4brwsr/emul/java_lang_String.js",
   102     processByteCode=false
   103 )
   104 public final class String
   105     implements java.io.Serializable, Comparable<String>, CharSequence
   106 {
   107     /** The value is used for character storage. */
   108     private final char value[];
   109 
   110     /** The offset is the first index of the storage that is used. */
   111     private final int offset;
   112 
   113     /** The count is the number of characters in the String. */
   114     private final int count;
   115 
   116     /** Cache the hash code for the string */
   117     private int hash; // Default to 0
   118 
   119     /** use serialVersionUID from JDK 1.0.2 for interoperability */
   120     private static final long serialVersionUID = -6849794470754667710L;
   121 
   122     /**
   123      * Class String is special cased within the Serialization Stream Protocol.
   124      *
   125      * A String instance is written initially into an ObjectOutputStream in the
   126      * following format:
   127      * <pre>
   128      *      <code>TC_STRING</code> (utf String)
   129      * </pre>
   130      * The String is written by method <code>DataOutput.writeUTF</code>.
   131      * A new handle is generated to  refer to all future references to the
   132      * string instance within the stream.
   133      */
   134 //    private static final ObjectStreamField[] serialPersistentFields =
   135 //        new ObjectStreamField[0];
   136 
   137     /**
   138      * Initializes a newly created {@code String} object so that it represents
   139      * an empty character sequence.  Note that use of this constructor is
   140      * unnecessary since Strings are immutable.
   141      */
   142     public String() {
   143         this.offset = 0;
   144         this.count = 0;
   145         this.value = new char[0];
   146     }
   147 
   148     /**
   149      * Initializes a newly created {@code String} object so that it represents
   150      * the same sequence of characters as the argument; in other words, the
   151      * newly created string is a copy of the argument string. Unless an
   152      * explicit copy of {@code original} is needed, use of this constructor is
   153      * unnecessary since Strings are immutable.
   154      *
   155      * @param  original
   156      *         A {@code String}
   157      */
   158     public String(String original) {
   159         int size = original.count;
   160         char[] originalValue = original.value;
   161         char[] v;
   162         if (originalValue.length > size) {
   163             // The array representing the String is bigger than the new
   164             // String itself.  Perhaps this constructor is being called
   165             // in order to trim the baggage, so make a copy of the array.
   166             int off = original.offset;
   167             v = AbstractStringBuilder.copyOfRange(originalValue, off, off+size);
   168         } else {
   169             // The array representing the String is the same
   170             // size as the String, so no point in making a copy.
   171             v = originalValue;
   172         }
   173         this.offset = 0;
   174         this.count = size;
   175         this.value = v;
   176     }
   177 
   178     /**
   179      * Allocates a new {@code String} so that it represents the sequence of
   180      * characters currently contained in the character array argument. The
   181      * contents of the character array are copied; subsequent modification of
   182      * the character array does not affect the newly created string.
   183      *
   184      * @param  value
   185      *         The initial value of the string
   186      */
   187     public String(char value[]) {
   188         int size = value.length;
   189         this.offset = 0;
   190         this.count = size;
   191         this.value = AbstractStringBuilder.copyOf(value, size);
   192     }
   193 
   194     /**
   195      * Allocates a new {@code String} that contains characters from a subarray
   196      * of the character array argument. The {@code offset} argument is the
   197      * index of the first character of the subarray and the {@code count}
   198      * argument specifies the length of the subarray. The contents of the
   199      * subarray are copied; subsequent modification of the character array does
   200      * not affect the newly created string.
   201      *
   202      * @param  value
   203      *         Array that is the source of characters
   204      *
   205      * @param  offset
   206      *         The initial offset
   207      *
   208      * @param  count
   209      *         The length
   210      *
   211      * @throws  IndexOutOfBoundsException
   212      *          If the {@code offset} and {@code count} arguments index
   213      *          characters outside the bounds of the {@code value} array
   214      */
   215     public String(char value[], int offset, int count) {
   216         if (offset < 0) {
   217             throw new StringIndexOutOfBoundsException(offset);
   218         }
   219         if (count < 0) {
   220             throw new StringIndexOutOfBoundsException(count);
   221         }
   222         // Note: offset or count might be near -1>>>1.
   223         if (offset > value.length - count) {
   224             throw new StringIndexOutOfBoundsException(offset + count);
   225         }
   226         this.offset = 0;
   227         this.count = count;
   228         this.value = AbstractStringBuilder.copyOfRange(value, offset, offset+count);
   229     }
   230 
   231     /**
   232      * Allocates a new {@code String} that contains characters from a subarray
   233      * of the <a href="Character.html#unicode">Unicode code point</a> array
   234      * argument.  The {@code offset} argument is the index of the first code
   235      * point of the subarray and the {@code count} argument specifies the
   236      * length of the subarray.  The contents of the subarray are converted to
   237      * {@code char}s; subsequent modification of the {@code int} array does not
   238      * affect the newly created string.
   239      *
   240      * @param  codePoints
   241      *         Array that is the source of Unicode code points
   242      *
   243      * @param  offset
   244      *         The initial offset
   245      *
   246      * @param  count
   247      *         The length
   248      *
   249      * @throws  IllegalArgumentException
   250      *          If any invalid Unicode code point is found in {@code
   251      *          codePoints}
   252      *
   253      * @throws  IndexOutOfBoundsException
   254      *          If the {@code offset} and {@code count} arguments index
   255      *          characters outside the bounds of the {@code codePoints} array
   256      *
   257      * @since  1.5
   258      */
   259     public String(int[] codePoints, int offset, int count) {
   260         if (offset < 0) {
   261             throw new StringIndexOutOfBoundsException(offset);
   262         }
   263         if (count < 0) {
   264             throw new StringIndexOutOfBoundsException(count);
   265         }
   266         // Note: offset or count might be near -1>>>1.
   267         if (offset > codePoints.length - count) {
   268             throw new StringIndexOutOfBoundsException(offset + count);
   269         }
   270 
   271         final int end = offset + count;
   272 
   273         // Pass 1: Compute precise size of char[]
   274         int n = count;
   275         for (int i = offset; i < end; i++) {
   276             int c = codePoints[i];
   277             if (Character.isBmpCodePoint(c))
   278                 continue;
   279             else if (Character.isValidCodePoint(c))
   280                 n++;
   281             else throw new IllegalArgumentException(Integer.toString(c));
   282         }
   283 
   284         // Pass 2: Allocate and fill in char[]
   285         final char[] v = new char[n];
   286 
   287         for (int i = offset, j = 0; i < end; i++, j++) {
   288             int c = codePoints[i];
   289             if (Character.isBmpCodePoint(c))
   290                 v[j] = (char) c;
   291             else
   292                 Character.toSurrogates(c, v, j++);
   293         }
   294 
   295         this.value  = v;
   296         this.count  = n;
   297         this.offset = 0;
   298     }
   299 
   300     /**
   301      * Allocates a new {@code String} constructed from a subarray of an array
   302      * of 8-bit integer values.
   303      *
   304      * <p> The {@code offset} argument is the index of the first byte of the
   305      * subarray, and the {@code count} argument specifies the length of the
   306      * subarray.
   307      *
   308      * <p> Each {@code byte} in the subarray is converted to a {@code char} as
   309      * specified in the method above.
   310      *
   311      * @deprecated This method does not properly convert bytes into characters.
   312      * As of JDK&nbsp;1.1, the preferred way to do this is via the
   313      * {@code String} constructors that take a {@link
   314      * java.nio.charset.Charset}, charset name, or that use the platform's
   315      * default charset.
   316      *
   317      * @param  ascii
   318      *         The bytes to be converted to characters
   319      *
   320      * @param  hibyte
   321      *         The top 8 bits of each 16-bit Unicode code unit
   322      *
   323      * @param  offset
   324      *         The initial offset
   325      * @param  count
   326      *         The length
   327      *
   328      * @throws  IndexOutOfBoundsException
   329      *          If the {@code offset} or {@code count} argument is invalid
   330      *
   331      * @see  #String(byte[], int)
   332      * @see  #String(byte[], int, int, java.lang.String)
   333      * @see  #String(byte[], int, int, java.nio.charset.Charset)
   334      * @see  #String(byte[], int, int)
   335      * @see  #String(byte[], java.lang.String)
   336      * @see  #String(byte[], java.nio.charset.Charset)
   337      * @see  #String(byte[])
   338      */
   339     @Deprecated
   340     public String(byte ascii[], int hibyte, int offset, int count) {
   341         checkBounds(ascii, offset, count);
   342         char value[] = new char[count];
   343 
   344         if (hibyte == 0) {
   345             for (int i = count ; i-- > 0 ;) {
   346                 value[i] = (char) (ascii[i + offset] & 0xff);
   347             }
   348         } else {
   349             hibyte <<= 8;
   350             for (int i = count ; i-- > 0 ;) {
   351                 value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
   352             }
   353         }
   354         this.offset = 0;
   355         this.count = count;
   356         this.value = value;
   357     }
   358 
   359     /**
   360      * Allocates a new {@code String} containing characters constructed from
   361      * an array of 8-bit integer values. Each character <i>c</i>in the
   362      * resulting string is constructed from the corresponding component
   363      * <i>b</i> in the byte array such that:
   364      *
   365      * <blockquote><pre>
   366      *     <b><i>c</i></b> == (char)(((hibyte &amp; 0xff) &lt;&lt; 8)
   367      *                         | (<b><i>b</i></b> &amp; 0xff))
   368      * </pre></blockquote>
   369      *
   370      * @deprecated  This method does not properly convert bytes into
   371      * characters.  As of JDK&nbsp;1.1, the preferred way to do this is via the
   372      * {@code String} constructors that take a {@link
   373      * java.nio.charset.Charset}, charset name, or that use the platform's
   374      * default charset.
   375      *
   376      * @param  ascii
   377      *         The bytes to be converted to characters
   378      *
   379      * @param  hibyte
   380      *         The top 8 bits of each 16-bit Unicode code unit
   381      *
   382      * @see  #String(byte[], int, int, java.lang.String)
   383      * @see  #String(byte[], int, int, java.nio.charset.Charset)
   384      * @see  #String(byte[], int, int)
   385      * @see  #String(byte[], java.lang.String)
   386      * @see  #String(byte[], java.nio.charset.Charset)
   387      * @see  #String(byte[])
   388      */
   389     @Deprecated
   390     public String(byte ascii[], int hibyte) {
   391         this(ascii, hibyte, 0, ascii.length);
   392     }
   393 
   394     /* Common private utility method used to bounds check the byte array
   395      * and requested offset & length values used by the String(byte[],..)
   396      * constructors.
   397      */
   398     private static void checkBounds(byte[] bytes, int offset, int length) {
   399         if (length < 0)
   400             throw new StringIndexOutOfBoundsException(length);
   401         if (offset < 0)
   402             throw new StringIndexOutOfBoundsException(offset);
   403         if (offset > bytes.length - length)
   404             throw new StringIndexOutOfBoundsException(offset + length);
   405     }
   406 
   407     /**
   408      * Constructs a new {@code String} by decoding the specified subarray of
   409      * bytes using the specified charset.  The length of the new {@code String}
   410      * is a function of the charset, and hence may not be equal to the length
   411      * of the subarray.
   412      *
   413      * <p> The behavior of this constructor when the given bytes are not valid
   414      * in the given charset is unspecified.  The {@link
   415      * java.nio.charset.CharsetDecoder} class should be used when more control
   416      * over the decoding process is required.
   417      *
   418      * @param  bytes
   419      *         The bytes to be decoded into characters
   420      *
   421      * @param  offset
   422      *         The index of the first byte to decode
   423      *
   424      * @param  length
   425      *         The number of bytes to decode
   426 
   427      * @param  charsetName
   428      *         The name of a supported {@linkplain java.nio.charset.Charset
   429      *         charset}
   430      *
   431      * @throws  UnsupportedEncodingException
   432      *          If the named charset is not supported
   433      *
   434      * @throws  IndexOutOfBoundsException
   435      *          If the {@code offset} and {@code length} arguments index
   436      *          characters outside the bounds of the {@code bytes} array
   437      *
   438      * @since  JDK1.1
   439      */
   440 //    public String(byte bytes[], int offset, int length, String charsetName)
   441 //        throws UnsupportedEncodingException
   442 //    {
   443 //        if (charsetName == null)
   444 //            throw new NullPointerException("charsetName");
   445 //        checkBounds(bytes, offset, length);
   446 //        char[] v = StringCoding.decode(charsetName, bytes, offset, length);
   447 //        this.offset = 0;
   448 //        this.count = v.length;
   449 //        this.value = v;
   450 //    }
   451 
   452     /**
   453      * Constructs a new {@code String} by decoding the specified subarray of
   454      * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
   455      * The length of the new {@code String} is a function of the charset, and
   456      * hence may not be equal to the length of the subarray.
   457      *
   458      * <p> This method always replaces malformed-input and unmappable-character
   459      * sequences with this charset's default replacement string.  The {@link
   460      * java.nio.charset.CharsetDecoder} class should be used when more control
   461      * over the decoding process is required.
   462      *
   463      * @param  bytes
   464      *         The bytes to be decoded into characters
   465      *
   466      * @param  offset
   467      *         The index of the first byte to decode
   468      *
   469      * @param  length
   470      *         The number of bytes to decode
   471      *
   472      * @param  charset
   473      *         The {@linkplain java.nio.charset.Charset charset} to be used to
   474      *         decode the {@code bytes}
   475      *
   476      * @throws  IndexOutOfBoundsException
   477      *          If the {@code offset} and {@code length} arguments index
   478      *          characters outside the bounds of the {@code bytes} array
   479      *
   480      * @since  1.6
   481      */
   482     /* don't want dependnecy on Charset
   483     public String(byte bytes[], int offset, int length, Charset charset) {
   484         if (charset == null)
   485             throw new NullPointerException("charset");
   486         checkBounds(bytes, offset, length);
   487         char[] v = StringCoding.decode(charset, bytes, offset, length);
   488         this.offset = 0;
   489         this.count = v.length;
   490         this.value = v;
   491     }
   492     */
   493 
   494     /**
   495      * Constructs a new {@code String} by decoding the specified array of bytes
   496      * using the specified {@linkplain java.nio.charset.Charset charset}.  The
   497      * length of the new {@code String} is a function of the charset, and hence
   498      * may not be equal to the length of the byte array.
   499      *
   500      * <p> The behavior of this constructor when the given bytes are not valid
   501      * in the given charset is unspecified.  The {@link
   502      * java.nio.charset.CharsetDecoder} class should be used when more control
   503      * over the decoding process is required.
   504      *
   505      * @param  bytes
   506      *         The bytes to be decoded into characters
   507      *
   508      * @param  charsetName
   509      *         The name of a supported {@linkplain java.nio.charset.Charset
   510      *         charset}
   511      *
   512      * @throws  UnsupportedEncodingException
   513      *          If the named charset is not supported
   514      *
   515      * @since  JDK1.1
   516      */
   517 //    public String(byte bytes[], String charsetName)
   518 //        throws UnsupportedEncodingException
   519 //    {
   520 //        this(bytes, 0, bytes.length, charsetName);
   521 //    }
   522 
   523     /**
   524      * Constructs a new {@code String} by decoding the specified array of
   525      * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
   526      * The length of the new {@code String} is a function of the charset, and
   527      * hence may not be equal to the length of the byte array.
   528      *
   529      * <p> This method always replaces malformed-input and unmappable-character
   530      * sequences with this charset's default replacement string.  The {@link
   531      * java.nio.charset.CharsetDecoder} class should be used when more control
   532      * over the decoding process is required.
   533      *
   534      * @param  bytes
   535      *         The bytes to be decoded into characters
   536      *
   537      * @param  charset
   538      *         The {@linkplain java.nio.charset.Charset charset} to be used to
   539      *         decode the {@code bytes}
   540      *
   541      * @since  1.6
   542      */
   543     /* don't want dep on Charset
   544     public String(byte bytes[], Charset charset) {
   545         this(bytes, 0, bytes.length, charset);
   546     }
   547     */
   548 
   549     /**
   550      * Constructs a new {@code String} by decoding the specified subarray of
   551      * bytes using the platform's default charset.  The length of the new
   552      * {@code String} is a function of the charset, and hence may not be equal
   553      * to the length of the subarray.
   554      *
   555      * <p> The behavior of this constructor when the given bytes are not valid
   556      * in the default charset is unspecified.  The {@link
   557      * java.nio.charset.CharsetDecoder} class should be used when more control
   558      * over the decoding process is required.
   559      *
   560      * @param  bytes
   561      *         The bytes to be decoded into characters
   562      *
   563      * @param  offset
   564      *         The index of the first byte to decode
   565      *
   566      * @param  length
   567      *         The number of bytes to decode
   568      *
   569      * @throws  IndexOutOfBoundsException
   570      *          If the {@code offset} and the {@code length} arguments index
   571      *          characters outside the bounds of the {@code bytes} array
   572      *
   573      * @since  JDK1.1
   574      */
   575     public String(byte bytes[], int offset, int length) {
   576         checkBounds(bytes, offset, length);
   577         char[] v  = new char[length];
   578         for (int i = 0; i < length; i++) {
   579             v[i] = (char)bytes[offset++];
   580         }
   581         this.offset = 0;
   582         this.count = v.length;
   583         this.value = v;
   584     }
   585 
   586     /**
   587      * Constructs a new {@code String} by decoding the specified array of bytes
   588      * using the platform's default charset.  The length of the new {@code
   589      * String} is a function of the charset, and hence may not be equal to the
   590      * length of the byte array.
   591      *
   592      * <p> The behavior of this constructor when the given bytes are not valid
   593      * in the default charset is unspecified.  The {@link
   594      * java.nio.charset.CharsetDecoder} class should be used when more control
   595      * over the decoding process is required.
   596      *
   597      * @param  bytes
   598      *         The bytes to be decoded into characters
   599      *
   600      * @since  JDK1.1
   601      */
   602     public String(byte bytes[]) {
   603         this(bytes, 0, bytes.length);
   604     }
   605 
   606     /**
   607      * Allocates a new string that contains the sequence of characters
   608      * currently contained in the string buffer argument. The contents of the
   609      * string buffer are copied; subsequent modification of the string buffer
   610      * does not affect the newly created string.
   611      *
   612      * @param  buffer
   613      *         A {@code StringBuffer}
   614      */
   615     public String(StringBuffer buffer) {
   616         String result = buffer.toString();
   617         this.value = result.value;
   618         this.count = result.count;
   619         this.offset = result.offset;
   620     }
   621 
   622     /**
   623      * Allocates a new string that contains the sequence of characters
   624      * currently contained in the string builder argument. The contents of the
   625      * string builder are copied; subsequent modification of the string builder
   626      * does not affect the newly created string.
   627      *
   628      * <p> This constructor is provided to ease migration to {@code
   629      * StringBuilder}. Obtaining a string from a string builder via the {@code
   630      * toString} method is likely to run faster and is generally preferred.
   631      *
   632      * @param   builder
   633      *          A {@code StringBuilder}
   634      *
   635      * @since  1.5
   636      */
   637     public String(StringBuilder builder) {
   638         String result = builder.toString();
   639         this.value = result.value;
   640         this.count = result.count;
   641         this.offset = result.offset;
   642     }
   643 
   644 
   645     // Package private constructor which shares value array for speed.
   646     String(int offset, int count, char value[]) {
   647         this.value = value;
   648         this.offset = offset;
   649         this.count = count;
   650     }
   651 
   652     /**
   653      * Returns the length of this string.
   654      * The length is equal to the number of <a href="Character.html#unicode">Unicode
   655      * code units</a> in the string.
   656      *
   657      * @return  the length of the sequence of characters represented by this
   658      *          object.
   659      */
   660     public int length() {
   661         return count;
   662     }
   663 
   664     /**
   665      * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
   666      *
   667      * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
   668      * <tt>false</tt>
   669      *
   670      * @since 1.6
   671      */
   672     public boolean isEmpty() {
   673         return count == 0;
   674     }
   675 
   676     /**
   677      * Returns the <code>char</code> value at the
   678      * specified index. An index ranges from <code>0</code> to
   679      * <code>length() - 1</code>. The first <code>char</code> value of the sequence
   680      * is at index <code>0</code>, the next at index <code>1</code>,
   681      * and so on, as for array indexing.
   682      *
   683      * <p>If the <code>char</code> value specified by the index is a
   684      * <a href="Character.html#unicode">surrogate</a>, the surrogate
   685      * value is returned.
   686      *
   687      * @param      index   the index of the <code>char</code> value.
   688      * @return     the <code>char</code> value at the specified index of this string.
   689      *             The first <code>char</code> value is at index <code>0</code>.
   690      * @exception  IndexOutOfBoundsException  if the <code>index</code>
   691      *             argument is negative or not less than the length of this
   692      *             string.
   693      */
   694     public char charAt(int index) {
   695         if ((index < 0) || (index >= count)) {
   696             throw new StringIndexOutOfBoundsException(index);
   697         }
   698         return value[index + offset];
   699     }
   700 
   701     /**
   702      * Returns the character (Unicode code point) at the specified
   703      * index. The index refers to <code>char</code> values
   704      * (Unicode code units) and ranges from <code>0</code> to
   705      * {@link #length()}<code> - 1</code>.
   706      *
   707      * <p> If the <code>char</code> value specified at the given index
   708      * is in the high-surrogate range, the following index is less
   709      * than the length of this <code>String</code>, and the
   710      * <code>char</code> value at the following index is in the
   711      * low-surrogate range, then the supplementary code point
   712      * corresponding to this surrogate pair is returned. Otherwise,
   713      * the <code>char</code> value at the given index is returned.
   714      *
   715      * @param      index the index to the <code>char</code> values
   716      * @return     the code point value of the character at the
   717      *             <code>index</code>
   718      * @exception  IndexOutOfBoundsException  if the <code>index</code>
   719      *             argument is negative or not less than the length of this
   720      *             string.
   721      * @since      1.5
   722      */
   723     public int codePointAt(int index) {
   724         if ((index < 0) || (index >= count)) {
   725             throw new StringIndexOutOfBoundsException(index);
   726         }
   727         return Character.codePointAtImpl(value, offset + index, offset + count);
   728     }
   729 
   730     /**
   731      * Returns the character (Unicode code point) before the specified
   732      * index. The index refers to <code>char</code> values
   733      * (Unicode code units) and ranges from <code>1</code> to {@link
   734      * CharSequence#length() length}.
   735      *
   736      * <p> If the <code>char</code> value at <code>(index - 1)</code>
   737      * is in the low-surrogate range, <code>(index - 2)</code> is not
   738      * negative, and the <code>char</code> value at <code>(index -
   739      * 2)</code> is in the high-surrogate range, then the
   740      * supplementary code point value of the surrogate pair is
   741      * returned. If the <code>char</code> value at <code>index -
   742      * 1</code> is an unpaired low-surrogate or a high-surrogate, the
   743      * surrogate value is returned.
   744      *
   745      * @param     index the index following the code point that should be returned
   746      * @return    the Unicode code point value before the given index.
   747      * @exception IndexOutOfBoundsException if the <code>index</code>
   748      *            argument is less than 1 or greater than the length
   749      *            of this string.
   750      * @since     1.5
   751      */
   752     public int codePointBefore(int index) {
   753         int i = index - 1;
   754         if ((i < 0) || (i >= count)) {
   755             throw new StringIndexOutOfBoundsException(index);
   756         }
   757         return Character.codePointBeforeImpl(value, offset + index, offset);
   758     }
   759 
   760     /**
   761      * Returns the number of Unicode code points in the specified text
   762      * range of this <code>String</code>. The text range begins at the
   763      * specified <code>beginIndex</code> and extends to the
   764      * <code>char</code> at index <code>endIndex - 1</code>. Thus the
   765      * length (in <code>char</code>s) of the text range is
   766      * <code>endIndex-beginIndex</code>. Unpaired surrogates within
   767      * the text range count as one code point each.
   768      *
   769      * @param beginIndex the index to the first <code>char</code> of
   770      * the text range.
   771      * @param endIndex the index after the last <code>char</code> of
   772      * the text range.
   773      * @return the number of Unicode code points in the specified text
   774      * range
   775      * @exception IndexOutOfBoundsException if the
   776      * <code>beginIndex</code> is negative, or <code>endIndex</code>
   777      * is larger than the length of this <code>String</code>, or
   778      * <code>beginIndex</code> is larger than <code>endIndex</code>.
   779      * @since  1.5
   780      */
   781     public int codePointCount(int beginIndex, int endIndex) {
   782         if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
   783             throw new IndexOutOfBoundsException();
   784         }
   785         return Character.codePointCountImpl(value, offset+beginIndex, endIndex-beginIndex);
   786     }
   787 
   788     /**
   789      * Returns the index within this <code>String</code> that is
   790      * offset from the given <code>index</code> by
   791      * <code>codePointOffset</code> code points. Unpaired surrogates
   792      * within the text range given by <code>index</code> and
   793      * <code>codePointOffset</code> count as one code point each.
   794      *
   795      * @param index the index to be offset
   796      * @param codePointOffset the offset in code points
   797      * @return the index within this <code>String</code>
   798      * @exception IndexOutOfBoundsException if <code>index</code>
   799      *   is negative or larger then the length of this
   800      *   <code>String</code>, or if <code>codePointOffset</code> is positive
   801      *   and the substring starting with <code>index</code> has fewer
   802      *   than <code>codePointOffset</code> code points,
   803      *   or if <code>codePointOffset</code> is negative and the substring
   804      *   before <code>index</code> has fewer than the absolute value
   805      *   of <code>codePointOffset</code> code points.
   806      * @since 1.5
   807      */
   808     public int offsetByCodePoints(int index, int codePointOffset) {
   809         if (index < 0 || index > count) {
   810             throw new IndexOutOfBoundsException();
   811         }
   812         return Character.offsetByCodePointsImpl(value, offset, count,
   813                                                 offset+index, codePointOffset) - offset;
   814     }
   815 
   816     /**
   817      * Copy characters from this string into dst starting at dstBegin.
   818      * This method doesn't perform any range checking.
   819      */
   820     void getChars(char dst[], int dstBegin) {
   821         AbstractStringBuilder.arraycopy(value, offset, dst, dstBegin, count);
   822     }
   823 
   824     /**
   825      * Copies characters from this string into the destination character
   826      * array.
   827      * <p>
   828      * The first character to be copied is at index <code>srcBegin</code>;
   829      * the last character to be copied is at index <code>srcEnd-1</code>
   830      * (thus the total number of characters to be copied is
   831      * <code>srcEnd-srcBegin</code>). The characters are copied into the
   832      * subarray of <code>dst</code> starting at index <code>dstBegin</code>
   833      * and ending at index:
   834      * <p><blockquote><pre>
   835      *     dstbegin + (srcEnd-srcBegin) - 1
   836      * </pre></blockquote>
   837      *
   838      * @param      srcBegin   index of the first character in the string
   839      *                        to copy.
   840      * @param      srcEnd     index after the last character in the string
   841      *                        to copy.
   842      * @param      dst        the destination array.
   843      * @param      dstBegin   the start offset in the destination array.
   844      * @exception IndexOutOfBoundsException If any of the following
   845      *            is true:
   846      *            <ul><li><code>srcBegin</code> is negative.
   847      *            <li><code>srcBegin</code> is greater than <code>srcEnd</code>
   848      *            <li><code>srcEnd</code> is greater than the length of this
   849      *                string
   850      *            <li><code>dstBegin</code> is negative
   851      *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
   852      *                <code>dst.length</code></ul>
   853      */
   854     public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
   855         if (srcBegin < 0) {
   856             throw new StringIndexOutOfBoundsException(srcBegin);
   857         }
   858         if (srcEnd > count) {
   859             throw new StringIndexOutOfBoundsException(srcEnd);
   860         }
   861         if (srcBegin > srcEnd) {
   862             throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
   863         }
   864         AbstractStringBuilder.arraycopy(value, offset + srcBegin, dst, dstBegin,
   865              srcEnd - srcBegin);
   866     }
   867 
   868     /**
   869      * Copies characters from this string into the destination byte array. Each
   870      * byte receives the 8 low-order bits of the corresponding character. The
   871      * eight high-order bits of each character are not copied and do not
   872      * participate in the transfer in any way.
   873      *
   874      * <p> The first character to be copied is at index {@code srcBegin}; the
   875      * last character to be copied is at index {@code srcEnd-1}.  The total
   876      * number of characters to be copied is {@code srcEnd-srcBegin}. The
   877      * characters, converted to bytes, are copied into the subarray of {@code
   878      * dst} starting at index {@code dstBegin} and ending at index:
   879      *
   880      * <blockquote><pre>
   881      *     dstbegin + (srcEnd-srcBegin) - 1
   882      * </pre></blockquote>
   883      *
   884      * @deprecated  This method does not properly convert characters into
   885      * bytes.  As of JDK&nbsp;1.1, the preferred way to do this is via the
   886      * {@link #getBytes()} method, which uses the platform's default charset.
   887      *
   888      * @param  srcBegin
   889      *         Index of the first character in the string to copy
   890      *
   891      * @param  srcEnd
   892      *         Index after the last character in the string to copy
   893      *
   894      * @param  dst
   895      *         The destination array
   896      *
   897      * @param  dstBegin
   898      *         The start offset in the destination array
   899      *
   900      * @throws  IndexOutOfBoundsException
   901      *          If any of the following is true:
   902      *          <ul>
   903      *            <li> {@code srcBegin} is negative
   904      *            <li> {@code srcBegin} is greater than {@code srcEnd}
   905      *            <li> {@code srcEnd} is greater than the length of this String
   906      *            <li> {@code dstBegin} is negative
   907      *            <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
   908      *                 dst.length}
   909      *          </ul>
   910      */
   911     @Deprecated
   912     public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
   913         if (srcBegin < 0) {
   914             throw new StringIndexOutOfBoundsException(srcBegin);
   915         }
   916         if (srcEnd > count) {
   917             throw new StringIndexOutOfBoundsException(srcEnd);
   918         }
   919         if (srcBegin > srcEnd) {
   920             throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
   921         }
   922         int j = dstBegin;
   923         int n = offset + srcEnd;
   924         int i = offset + srcBegin;
   925         char[] val = value;   /* avoid getfield opcode */
   926 
   927         while (i < n) {
   928             dst[j++] = (byte)val[i++];
   929         }
   930     }
   931 
   932     /**
   933      * Encodes this {@code String} into a sequence of bytes using the named
   934      * charset, storing the result into a new byte array.
   935      *
   936      * <p> The behavior of this method when this string cannot be encoded in
   937      * the given charset is unspecified.  The {@link
   938      * java.nio.charset.CharsetEncoder} class should be used when more control
   939      * over the encoding process is required.
   940      *
   941      * @param  charsetName
   942      *         The name of a supported {@linkplain java.nio.charset.Charset
   943      *         charset}
   944      *
   945      * @return  The resultant byte array
   946      *
   947      * @throws  UnsupportedEncodingException
   948      *          If the named charset is not supported
   949      *
   950      * @since  JDK1.1
   951      */
   952 //    public byte[] getBytes(String charsetName)
   953 //        throws UnsupportedEncodingException
   954 //    {
   955 //        if (charsetName == null) throw new NullPointerException();
   956 //        return StringCoding.encode(charsetName, value, offset, count);
   957 //    }
   958 
   959     /**
   960      * Encodes this {@code String} into a sequence of bytes using the given
   961      * {@linkplain java.nio.charset.Charset charset}, storing the result into a
   962      * new byte array.
   963      *
   964      * <p> This method always replaces malformed-input and unmappable-character
   965      * sequences with this charset's default replacement byte array.  The
   966      * {@link java.nio.charset.CharsetEncoder} class should be used when more
   967      * control over the encoding process is required.
   968      *
   969      * @param  charset
   970      *         The {@linkplain java.nio.charset.Charset} to be used to encode
   971      *         the {@code String}
   972      *
   973      * @return  The resultant byte array
   974      *
   975      * @since  1.6
   976      */
   977     /* don't want dep on Charset
   978     public byte[] getBytes(Charset charset) {
   979         if (charset == null) throw new NullPointerException();
   980         return StringCoding.encode(charset, value, offset, count);
   981     }
   982     */
   983 
   984     /**
   985      * Encodes this {@code String} into a sequence of bytes using the
   986      * platform's default charset, storing the result into a new byte array.
   987      *
   988      * <p> The behavior of this method when this string cannot be encoded in
   989      * the default charset is unspecified.  The {@link
   990      * java.nio.charset.CharsetEncoder} class should be used when more control
   991      * over the encoding process is required.
   992      *
   993      * @return  The resultant byte array
   994      *
   995      * @since      JDK1.1
   996      */
   997     public byte[] getBytes() {
   998         byte[] arr = new byte[length()];
   999         for (int i = 0; i < arr.length; i++) {
  1000             final char v = charAt(i);
  1001             arr[i] = (byte)v;
  1002         }
  1003         return arr;
  1004     }
  1005 
  1006     /**
  1007      * Compares this string to the specified object.  The result is {@code
  1008      * true} if and only if the argument is not {@code null} and is a {@code
  1009      * String} object that represents the same sequence of characters as this
  1010      * object.
  1011      *
  1012      * @param  anObject
  1013      *         The object to compare this {@code String} against
  1014      *
  1015      * @return  {@code true} if the given object represents a {@code String}
  1016      *          equivalent to this string, {@code false} otherwise
  1017      *
  1018      * @see  #compareTo(String)
  1019      * @see  #equalsIgnoreCase(String)
  1020      */
  1021     public boolean equals(Object anObject) {
  1022         if (this == anObject) {
  1023             return true;
  1024         }
  1025         if (anObject instanceof String) {
  1026             String anotherString = (String)anObject;
  1027             int n = count;
  1028             if (n == anotherString.count) {
  1029                 char v1[] = value;
  1030                 char v2[] = anotherString.value;
  1031                 int i = offset;
  1032                 int j = anotherString.offset;
  1033                 while (n-- != 0) {
  1034                     if (v1[i++] != v2[j++])
  1035                         return false;
  1036                 }
  1037                 return true;
  1038             }
  1039         }
  1040         return false;
  1041     }
  1042 
  1043     /**
  1044      * Compares this string to the specified {@code StringBuffer}.  The result
  1045      * is {@code true} if and only if this {@code String} represents the same
  1046      * sequence of characters as the specified {@code StringBuffer}.
  1047      *
  1048      * @param  sb
  1049      *         The {@code StringBuffer} to compare this {@code String} against
  1050      *
  1051      * @return  {@code true} if this {@code String} represents the same
  1052      *          sequence of characters as the specified {@code StringBuffer},
  1053      *          {@code false} otherwise
  1054      *
  1055      * @since  1.4
  1056      */
  1057     public boolean contentEquals(StringBuffer sb) {
  1058         synchronized(sb) {
  1059             return contentEquals((CharSequence)sb);
  1060         }
  1061     }
  1062 
  1063     /**
  1064      * Compares this string to the specified {@code CharSequence}.  The result
  1065      * is {@code true} if and only if this {@code String} represents the same
  1066      * sequence of char values as the specified sequence.
  1067      *
  1068      * @param  cs
  1069      *         The sequence to compare this {@code String} against
  1070      *
  1071      * @return  {@code true} if this {@code String} represents the same
  1072      *          sequence of char values as the specified sequence, {@code
  1073      *          false} otherwise
  1074      *
  1075      * @since  1.5
  1076      */
  1077     public boolean contentEquals(CharSequence cs) {
  1078         if (count != cs.length())
  1079             return false;
  1080         // Argument is a StringBuffer, StringBuilder
  1081         if (cs instanceof AbstractStringBuilder) {
  1082             char v1[] = value;
  1083             char v2[] = ((AbstractStringBuilder)cs).getValue();
  1084             int i = offset;
  1085             int j = 0;
  1086             int n = count;
  1087             while (n-- != 0) {
  1088                 if (v1[i++] != v2[j++])
  1089                     return false;
  1090             }
  1091             return true;
  1092         }
  1093         // Argument is a String
  1094         if (cs.equals(this))
  1095             return true;
  1096         // Argument is a generic CharSequence
  1097         char v1[] = value;
  1098         int i = offset;
  1099         int j = 0;
  1100         int n = count;
  1101         while (n-- != 0) {
  1102             if (v1[i++] != cs.charAt(j++))
  1103                 return false;
  1104         }
  1105         return true;
  1106     }
  1107 
  1108     /**
  1109      * Compares this {@code String} to another {@code String}, ignoring case
  1110      * considerations.  Two strings are considered equal ignoring case if they
  1111      * are of the same length and corresponding characters in the two strings
  1112      * are equal ignoring case.
  1113      *
  1114      * <p> Two characters {@code c1} and {@code c2} are considered the same
  1115      * ignoring case if at least one of the following is true:
  1116      * <ul>
  1117      *   <li> The two characters are the same (as compared by the
  1118      *        {@code ==} operator)
  1119      *   <li> Applying the method {@link
  1120      *        java.lang.Character#toUpperCase(char)} to each character
  1121      *        produces the same result
  1122      *   <li> Applying the method {@link
  1123      *        java.lang.Character#toLowerCase(char)} to each character
  1124      *        produces the same result
  1125      * </ul>
  1126      *
  1127      * @param  anotherString
  1128      *         The {@code String} to compare this {@code String} against
  1129      *
  1130      * @return  {@code true} if the argument is not {@code null} and it
  1131      *          represents an equivalent {@code String} ignoring case; {@code
  1132      *          false} otherwise
  1133      *
  1134      * @see  #equals(Object)
  1135      */
  1136     public boolean equalsIgnoreCase(String anotherString) {
  1137         return (this == anotherString) ? true :
  1138                (anotherString != null) && (anotherString.count == count) &&
  1139                regionMatches(true, 0, anotherString, 0, count);
  1140     }
  1141 
  1142     /**
  1143      * Compares two strings lexicographically.
  1144      * The comparison is based on the Unicode value of each character in
  1145      * the strings. The character sequence represented by this
  1146      * <code>String</code> object is compared lexicographically to the
  1147      * character sequence represented by the argument string. The result is
  1148      * a negative integer if this <code>String</code> object
  1149      * lexicographically precedes the argument string. The result is a
  1150      * positive integer if this <code>String</code> object lexicographically
  1151      * follows the argument string. The result is zero if the strings
  1152      * are equal; <code>compareTo</code> returns <code>0</code> exactly when
  1153      * the {@link #equals(Object)} method would return <code>true</code>.
  1154      * <p>
  1155      * This is the definition of lexicographic ordering. If two strings are
  1156      * different, then either they have different characters at some index
  1157      * that is a valid index for both strings, or their lengths are different,
  1158      * or both. If they have different characters at one or more index
  1159      * positions, let <i>k</i> be the smallest such index; then the string
  1160      * whose character at position <i>k</i> has the smaller value, as
  1161      * determined by using the &lt; operator, lexicographically precedes the
  1162      * other string. In this case, <code>compareTo</code> returns the
  1163      * difference of the two character values at position <code>k</code> in
  1164      * the two string -- that is, the value:
  1165      * <blockquote><pre>
  1166      * this.charAt(k)-anotherString.charAt(k)
  1167      * </pre></blockquote>
  1168      * If there is no index position at which they differ, then the shorter
  1169      * string lexicographically precedes the longer string. In this case,
  1170      * <code>compareTo</code> returns the difference of the lengths of the
  1171      * strings -- that is, the value:
  1172      * <blockquote><pre>
  1173      * this.length()-anotherString.length()
  1174      * </pre></blockquote>
  1175      *
  1176      * @param   anotherString   the <code>String</code> to be compared.
  1177      * @return  the value <code>0</code> if the argument string is equal to
  1178      *          this string; a value less than <code>0</code> if this string
  1179      *          is lexicographically less than the string argument; and a
  1180      *          value greater than <code>0</code> if this string is
  1181      *          lexicographically greater than the string argument.
  1182      */
  1183     public int compareTo(String anotherString) {
  1184         int len1 = count;
  1185         int len2 = anotherString.count;
  1186         int n = Math.min(len1, len2);
  1187         char v1[] = value;
  1188         char v2[] = anotherString.value;
  1189         int i = offset;
  1190         int j = anotherString.offset;
  1191 
  1192         if (i == j) {
  1193             int k = i;
  1194             int lim = n + i;
  1195             while (k < lim) {
  1196                 char c1 = v1[k];
  1197                 char c2 = v2[k];
  1198                 if (c1 != c2) {
  1199                     return c1 - c2;
  1200                 }
  1201                 k++;
  1202             }
  1203         } else {
  1204             while (n-- != 0) {
  1205                 char c1 = v1[i++];
  1206                 char c2 = v2[j++];
  1207                 if (c1 != c2) {
  1208                     return c1 - c2;
  1209                 }
  1210             }
  1211         }
  1212         return len1 - len2;
  1213     }
  1214 
  1215     /**
  1216      * A Comparator that orders <code>String</code> objects as by
  1217      * <code>compareToIgnoreCase</code>. This comparator is serializable.
  1218      * <p>
  1219      * Note that this Comparator does <em>not</em> take locale into account,
  1220      * and will result in an unsatisfactory ordering for certain locales.
  1221      * The java.text package provides <em>Collators</em> to allow
  1222      * locale-sensitive ordering.
  1223      *
  1224      * @see     java.text.Collator#compare(String, String)
  1225      * @since   1.2
  1226      */
  1227     public static final Comparator<String> CASE_INSENSITIVE_ORDER
  1228                                          = new CaseInsensitiveComparator();
  1229     private static class CaseInsensitiveComparator
  1230                          implements Comparator<String>, java.io.Serializable {
  1231         // use serialVersionUID from JDK 1.2.2 for interoperability
  1232         private static final long serialVersionUID = 8575799808933029326L;
  1233 
  1234         public int compare(String s1, String s2) {
  1235             int n1 = s1.length();
  1236             int n2 = s2.length();
  1237             int min = Math.min(n1, n2);
  1238             for (int i = 0; i < min; i++) {
  1239                 char c1 = s1.charAt(i);
  1240                 char c2 = s2.charAt(i);
  1241                 if (c1 != c2) {
  1242                     c1 = Character.toUpperCase(c1);
  1243                     c2 = Character.toUpperCase(c2);
  1244                     if (c1 != c2) {
  1245                         c1 = Character.toLowerCase(c1);
  1246                         c2 = Character.toLowerCase(c2);
  1247                         if (c1 != c2) {
  1248                             // No overflow because of numeric promotion
  1249                             return c1 - c2;
  1250                         }
  1251                     }
  1252                 }
  1253             }
  1254             return n1 - n2;
  1255         }
  1256     }
  1257 
  1258     /**
  1259      * Compares two strings lexicographically, ignoring case
  1260      * differences. This method returns an integer whose sign is that of
  1261      * calling <code>compareTo</code> with normalized versions of the strings
  1262      * where case differences have been eliminated by calling
  1263      * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
  1264      * each character.
  1265      * <p>
  1266      * Note that this method does <em>not</em> take locale into account,
  1267      * and will result in an unsatisfactory ordering for certain locales.
  1268      * The java.text package provides <em>collators</em> to allow
  1269      * locale-sensitive ordering.
  1270      *
  1271      * @param   str   the <code>String</code> to be compared.
  1272      * @return  a negative integer, zero, or a positive integer as the
  1273      *          specified String is greater than, equal to, or less
  1274      *          than this String, ignoring case considerations.
  1275      * @see     java.text.Collator#compare(String, String)
  1276      * @since   1.2
  1277      */
  1278     public int compareToIgnoreCase(String str) {
  1279         return CASE_INSENSITIVE_ORDER.compare(this, str);
  1280     }
  1281 
  1282     /**
  1283      * Tests if two string regions are equal.
  1284      * <p>
  1285      * A substring of this <tt>String</tt> object is compared to a substring
  1286      * of the argument other. The result is true if these substrings
  1287      * represent identical character sequences. The substring of this
  1288      * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
  1289      * and has length <tt>len</tt>. The substring of other to be compared
  1290      * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
  1291      * result is <tt>false</tt> if and only if at least one of the following
  1292      * is true:
  1293      * <ul><li><tt>toffset</tt> is negative.
  1294      * <li><tt>ooffset</tt> is negative.
  1295      * <li><tt>toffset+len</tt> is greater than the length of this
  1296      * <tt>String</tt> object.
  1297      * <li><tt>ooffset+len</tt> is greater than the length of the other
  1298      * argument.
  1299      * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
  1300      * such that:
  1301      * <tt>this.charAt(toffset+<i>k</i>)&nbsp;!=&nbsp;other.charAt(ooffset+<i>k</i>)</tt>
  1302      * </ul>
  1303      *
  1304      * @param   toffset   the starting offset of the subregion in this string.
  1305      * @param   other     the string argument.
  1306      * @param   ooffset   the starting offset of the subregion in the string
  1307      *                    argument.
  1308      * @param   len       the number of characters to compare.
  1309      * @return  <code>true</code> if the specified subregion of this string
  1310      *          exactly matches the specified subregion of the string argument;
  1311      *          <code>false</code> otherwise.
  1312      */
  1313     public boolean regionMatches(int toffset, String other, int ooffset,
  1314                                  int len) {
  1315         char ta[] = value;
  1316         int to = offset + toffset;
  1317         char pa[] = other.value;
  1318         int po = other.offset + ooffset;
  1319         // Note: toffset, ooffset, or len might be near -1>>>1.
  1320         if ((ooffset < 0) || (toffset < 0) || (toffset > (long)count - len)
  1321             || (ooffset > (long)other.count - len)) {
  1322             return false;
  1323         }
  1324         while (len-- > 0) {
  1325             if (ta[to++] != pa[po++]) {
  1326                 return false;
  1327             }
  1328         }
  1329         return true;
  1330     }
  1331 
  1332     /**
  1333      * Tests if two string regions are equal.
  1334      * <p>
  1335      * A substring of this <tt>String</tt> object is compared to a substring
  1336      * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
  1337      * substrings represent character sequences that are the same, ignoring
  1338      * case if and only if <tt>ignoreCase</tt> is true. The substring of
  1339      * this <tt>String</tt> object to be compared begins at index
  1340      * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
  1341      * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
  1342      * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
  1343      * at least one of the following is true:
  1344      * <ul><li><tt>toffset</tt> is negative.
  1345      * <li><tt>ooffset</tt> is negative.
  1346      * <li><tt>toffset+len</tt> is greater than the length of this
  1347      * <tt>String</tt> object.
  1348      * <li><tt>ooffset+len</tt> is greater than the length of the other
  1349      * argument.
  1350      * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
  1351      * integer <i>k</i> less than <tt>len</tt> such that:
  1352      * <blockquote><pre>
  1353      * this.charAt(toffset+k) != other.charAt(ooffset+k)
  1354      * </pre></blockquote>
  1355      * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
  1356      * integer <i>k</i> less than <tt>len</tt> such that:
  1357      * <blockquote><pre>
  1358      * Character.toLowerCase(this.charAt(toffset+k)) !=
  1359                Character.toLowerCase(other.charAt(ooffset+k))
  1360      * </pre></blockquote>
  1361      * and:
  1362      * <blockquote><pre>
  1363      * Character.toUpperCase(this.charAt(toffset+k)) !=
  1364      *         Character.toUpperCase(other.charAt(ooffset+k))
  1365      * </pre></blockquote>
  1366      * </ul>
  1367      *
  1368      * @param   ignoreCase   if <code>true</code>, ignore case when comparing
  1369      *                       characters.
  1370      * @param   toffset      the starting offset of the subregion in this
  1371      *                       string.
  1372      * @param   other        the string argument.
  1373      * @param   ooffset      the starting offset of the subregion in the string
  1374      *                       argument.
  1375      * @param   len          the number of characters to compare.
  1376      * @return  <code>true</code> if the specified subregion of this string
  1377      *          matches the specified subregion of the string argument;
  1378      *          <code>false</code> otherwise. Whether the matching is exact
  1379      *          or case insensitive depends on the <code>ignoreCase</code>
  1380      *          argument.
  1381      */
  1382     public boolean regionMatches(boolean ignoreCase, int toffset,
  1383                            String other, int ooffset, int len) {
  1384         char ta[] = value;
  1385         int to = offset + toffset;
  1386         char pa[] = other.value;
  1387         int po = other.offset + ooffset;
  1388         // Note: toffset, ooffset, or len might be near -1>>>1.
  1389         if ((ooffset < 0) || (toffset < 0) || (toffset > (long)count - len) ||
  1390                 (ooffset > (long)other.count - len)) {
  1391             return false;
  1392         }
  1393         while (len-- > 0) {
  1394             char c1 = ta[to++];
  1395             char c2 = pa[po++];
  1396             if (c1 == c2) {
  1397                 continue;
  1398             }
  1399             if (ignoreCase) {
  1400                 // If characters don't match but case may be ignored,
  1401                 // try converting both characters to uppercase.
  1402                 // If the results match, then the comparison scan should
  1403                 // continue.
  1404                 char u1 = Character.toUpperCase(c1);
  1405                 char u2 = Character.toUpperCase(c2);
  1406                 if (u1 == u2) {
  1407                     continue;
  1408                 }
  1409                 // Unfortunately, conversion to uppercase does not work properly
  1410                 // for the Georgian alphabet, which has strange rules about case
  1411                 // conversion.  So we need to make one last check before
  1412                 // exiting.
  1413                 if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
  1414                     continue;
  1415                 }
  1416             }
  1417             return false;
  1418         }
  1419         return true;
  1420     }
  1421 
  1422     /**
  1423      * Tests if the substring of this string beginning at the
  1424      * specified index starts with the specified prefix.
  1425      *
  1426      * @param   prefix    the prefix.
  1427      * @param   toffset   where to begin looking in this string.
  1428      * @return  <code>true</code> if the character sequence represented by the
  1429      *          argument is a prefix of the substring of this object starting
  1430      *          at index <code>toffset</code>; <code>false</code> otherwise.
  1431      *          The result is <code>false</code> if <code>toffset</code> is
  1432      *          negative or greater than the length of this
  1433      *          <code>String</code> object; otherwise the result is the same
  1434      *          as the result of the expression
  1435      *          <pre>
  1436      *          this.substring(toffset).startsWith(prefix)
  1437      *          </pre>
  1438      */
  1439     public boolean startsWith(String prefix, int toffset) {
  1440         char ta[] = value;
  1441         int to = offset + toffset;
  1442         char pa[] = prefix.value;
  1443         int po = prefix.offset;
  1444         int pc = prefix.count;
  1445         // Note: toffset might be near -1>>>1.
  1446         if ((toffset < 0) || (toffset > count - pc)) {
  1447             return false;
  1448         }
  1449         while (--pc >= 0) {
  1450             if (ta[to++] != pa[po++]) {
  1451                 return false;
  1452             }
  1453         }
  1454         return true;
  1455     }
  1456 
  1457     /**
  1458      * Tests if this string starts with the specified prefix.
  1459      *
  1460      * @param   prefix   the prefix.
  1461      * @return  <code>true</code> if the character sequence represented by the
  1462      *          argument is a prefix of the character sequence represented by
  1463      *          this string; <code>false</code> otherwise.
  1464      *          Note also that <code>true</code> will be returned if the
  1465      *          argument is an empty string or is equal to this
  1466      *          <code>String</code> object as determined by the
  1467      *          {@link #equals(Object)} method.
  1468      * @since   1. 0
  1469      */
  1470     public boolean startsWith(String prefix) {
  1471         return startsWith(prefix, 0);
  1472     }
  1473 
  1474     /**
  1475      * Tests if this string ends with the specified suffix.
  1476      *
  1477      * @param   suffix   the suffix.
  1478      * @return  <code>true</code> if the character sequence represented by the
  1479      *          argument is a suffix of the character sequence represented by
  1480      *          this object; <code>false</code> otherwise. Note that the
  1481      *          result will be <code>true</code> if the argument is the
  1482      *          empty string or is equal to this <code>String</code> object
  1483      *          as determined by the {@link #equals(Object)} method.
  1484      */
  1485     public boolean endsWith(String suffix) {
  1486         return startsWith(suffix, count - suffix.count);
  1487     }
  1488 
  1489     /**
  1490      * Returns a hash code for this string. The hash code for a
  1491      * <code>String</code> object is computed as
  1492      * <blockquote><pre>
  1493      * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
  1494      * </pre></blockquote>
  1495      * using <code>int</code> arithmetic, where <code>s[i]</code> is the
  1496      * <i>i</i>th character of the string, <code>n</code> is the length of
  1497      * the string, and <code>^</code> indicates exponentiation.
  1498      * (The hash value of the empty string is zero.)
  1499      *
  1500      * @return  a hash code value for this object.
  1501      */
  1502     public int hashCode() {
  1503         int h = hash;
  1504         if (h == 0 && count > 0) {
  1505             int off = offset;
  1506             char val[] = value;
  1507             int len = count;
  1508 
  1509             for (int i = 0; i < len; i++) {
  1510                 h = 31*h + val[off++];
  1511             }
  1512             hash = h;
  1513         }
  1514         return h;
  1515     }
  1516 
  1517     /**
  1518      * Returns the index within this string of the first occurrence of
  1519      * the specified character. If a character with value
  1520      * <code>ch</code> occurs in the character sequence represented by
  1521      * this <code>String</code> object, then the index (in Unicode
  1522      * code units) of the first such occurrence is returned. For
  1523      * values of <code>ch</code> in the range from 0 to 0xFFFF
  1524      * (inclusive), this is the smallest value <i>k</i> such that:
  1525      * <blockquote><pre>
  1526      * this.charAt(<i>k</i>) == ch
  1527      * </pre></blockquote>
  1528      * is true. For other values of <code>ch</code>, it is the
  1529      * smallest value <i>k</i> such that:
  1530      * <blockquote><pre>
  1531      * this.codePointAt(<i>k</i>) == ch
  1532      * </pre></blockquote>
  1533      * is true. In either case, if no such character occurs in this
  1534      * string, then <code>-1</code> is returned.
  1535      *
  1536      * @param   ch   a character (Unicode code point).
  1537      * @return  the index of the first occurrence of the character in the
  1538      *          character sequence represented by this object, or
  1539      *          <code>-1</code> if the character does not occur.
  1540      */
  1541     public int indexOf(int ch) {
  1542         return indexOf(ch, 0);
  1543     }
  1544 
  1545     /**
  1546      * Returns the index within this string of the first occurrence of the
  1547      * specified character, starting the search at the specified index.
  1548      * <p>
  1549      * If a character with value <code>ch</code> occurs in the
  1550      * character sequence represented by this <code>String</code>
  1551      * object at an index no smaller than <code>fromIndex</code>, then
  1552      * the index of the first such occurrence is returned. For values
  1553      * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
  1554      * this is the smallest value <i>k</i> such that:
  1555      * <blockquote><pre>
  1556      * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
  1557      * </pre></blockquote>
  1558      * is true. For other values of <code>ch</code>, it is the
  1559      * smallest value <i>k</i> such that:
  1560      * <blockquote><pre>
  1561      * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
  1562      * </pre></blockquote>
  1563      * is true. In either case, if no such character occurs in this
  1564      * string at or after position <code>fromIndex</code>, then
  1565      * <code>-1</code> is returned.
  1566      *
  1567      * <p>
  1568      * There is no restriction on the value of <code>fromIndex</code>. If it
  1569      * is negative, it has the same effect as if it were zero: this entire
  1570      * string may be searched. If it is greater than the length of this
  1571      * string, it has the same effect as if it were equal to the length of
  1572      * this string: <code>-1</code> is returned.
  1573      *
  1574      * <p>All indices are specified in <code>char</code> values
  1575      * (Unicode code units).
  1576      *
  1577      * @param   ch          a character (Unicode code point).
  1578      * @param   fromIndex   the index to start the search from.
  1579      * @return  the index of the first occurrence of the character in the
  1580      *          character sequence represented by this object that is greater
  1581      *          than or equal to <code>fromIndex</code>, or <code>-1</code>
  1582      *          if the character does not occur.
  1583      */
  1584     public int indexOf(int ch, int fromIndex) {
  1585         if (fromIndex < 0) {
  1586             fromIndex = 0;
  1587         } else if (fromIndex >= count) {
  1588             // Note: fromIndex might be near -1>>>1.
  1589             return -1;
  1590         }
  1591 
  1592         if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
  1593             // handle most cases here (ch is a BMP code point or a
  1594             // negative value (invalid code point))
  1595             final char[] value = this.value;
  1596             final int offset = this.offset;
  1597             final int max = offset + count;
  1598             for (int i = offset + fromIndex; i < max ; i++) {
  1599                 if (value[i] == ch) {
  1600                     return i - offset;
  1601                 }
  1602             }
  1603             return -1;
  1604         } else {
  1605             return indexOfSupplementary(ch, fromIndex);
  1606         }
  1607     }
  1608 
  1609     /**
  1610      * Handles (rare) calls of indexOf with a supplementary character.
  1611      */
  1612     private int indexOfSupplementary(int ch, int fromIndex) {
  1613         if (Character.isValidCodePoint(ch)) {
  1614             final char[] value = this.value;
  1615             final int offset = this.offset;
  1616             final char hi = Character.highSurrogate(ch);
  1617             final char lo = Character.lowSurrogate(ch);
  1618             final int max = offset + count - 1;
  1619             for (int i = offset + fromIndex; i < max; i++) {
  1620                 if (value[i] == hi && value[i+1] == lo) {
  1621                     return i - offset;
  1622                 }
  1623             }
  1624         }
  1625         return -1;
  1626     }
  1627 
  1628     /**
  1629      * Returns the index within this string of the last occurrence of
  1630      * the specified character. For values of <code>ch</code> in the
  1631      * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
  1632      * units) returned is the largest value <i>k</i> such that:
  1633      * <blockquote><pre>
  1634      * this.charAt(<i>k</i>) == ch
  1635      * </pre></blockquote>
  1636      * is true. For other values of <code>ch</code>, it is the
  1637      * largest value <i>k</i> such that:
  1638      * <blockquote><pre>
  1639      * this.codePointAt(<i>k</i>) == ch
  1640      * </pre></blockquote>
  1641      * is true.  In either case, if no such character occurs in this
  1642      * string, then <code>-1</code> is returned.  The
  1643      * <code>String</code> is searched backwards starting at the last
  1644      * character.
  1645      *
  1646      * @param   ch   a character (Unicode code point).
  1647      * @return  the index of the last occurrence of the character in the
  1648      *          character sequence represented by this object, or
  1649      *          <code>-1</code> if the character does not occur.
  1650      */
  1651     public int lastIndexOf(int ch) {
  1652         return lastIndexOf(ch, count - 1);
  1653     }
  1654 
  1655     /**
  1656      * Returns the index within this string of the last occurrence of
  1657      * the specified character, searching backward starting at the
  1658      * specified index. For values of <code>ch</code> in the range
  1659      * from 0 to 0xFFFF (inclusive), the index returned is the largest
  1660      * value <i>k</i> such that:
  1661      * <blockquote><pre>
  1662      * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
  1663      * </pre></blockquote>
  1664      * is true. For other values of <code>ch</code>, it is the
  1665      * largest value <i>k</i> such that:
  1666      * <blockquote><pre>
  1667      * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
  1668      * </pre></blockquote>
  1669      * is true. In either case, if no such character occurs in this
  1670      * string at or before position <code>fromIndex</code>, then
  1671      * <code>-1</code> is returned.
  1672      *
  1673      * <p>All indices are specified in <code>char</code> values
  1674      * (Unicode code units).
  1675      *
  1676      * @param   ch          a character (Unicode code point).
  1677      * @param   fromIndex   the index to start the search from. There is no
  1678      *          restriction on the value of <code>fromIndex</code>. If it is
  1679      *          greater than or equal to the length of this string, it has
  1680      *          the same effect as if it were equal to one less than the
  1681      *          length of this string: this entire string may be searched.
  1682      *          If it is negative, it has the same effect as if it were -1:
  1683      *          -1 is returned.
  1684      * @return  the index of the last occurrence of the character in the
  1685      *          character sequence represented by this object that is less
  1686      *          than or equal to <code>fromIndex</code>, or <code>-1</code>
  1687      *          if the character does not occur before that point.
  1688      */
  1689     public int lastIndexOf(int ch, int fromIndex) {
  1690         if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
  1691             // handle most cases here (ch is a BMP code point or a
  1692             // negative value (invalid code point))
  1693             final char[] value = this.value;
  1694             final int offset = this.offset;
  1695             int i = offset + Math.min(fromIndex, count - 1);
  1696             for (; i >= offset ; i--) {
  1697                 if (value[i] == ch) {
  1698                     return i - offset;
  1699                 }
  1700             }
  1701             return -1;
  1702         } else {
  1703             return lastIndexOfSupplementary(ch, fromIndex);
  1704         }
  1705     }
  1706 
  1707     /**
  1708      * Handles (rare) calls of lastIndexOf with a supplementary character.
  1709      */
  1710     private int lastIndexOfSupplementary(int ch, int fromIndex) {
  1711         if (Character.isValidCodePoint(ch)) {
  1712             final char[] value = this.value;
  1713             final int offset = this.offset;
  1714             char hi = Character.highSurrogate(ch);
  1715             char lo = Character.lowSurrogate(ch);
  1716             int i = offset + Math.min(fromIndex, count - 2);
  1717             for (; i >= offset; i--) {
  1718                 if (value[i] == hi && value[i+1] == lo) {
  1719                     return i - offset;
  1720                 }
  1721             }
  1722         }
  1723         return -1;
  1724     }
  1725 
  1726     /**
  1727      * Returns the index within this string of the first occurrence of the
  1728      * specified substring.
  1729      *
  1730      * <p>The returned index is the smallest value <i>k</i> for which:
  1731      * <blockquote><pre>
  1732      * this.startsWith(str, <i>k</i>)
  1733      * </pre></blockquote>
  1734      * If no such value of <i>k</i> exists, then {@code -1} is returned.
  1735      *
  1736      * @param   str   the substring to search for.
  1737      * @return  the index of the first occurrence of the specified substring,
  1738      *          or {@code -1} if there is no such occurrence.
  1739      */
  1740     public int indexOf(String str) {
  1741         return indexOf(str, 0);
  1742     }
  1743 
  1744     /**
  1745      * Returns the index within this string of the first occurrence of the
  1746      * specified substring, starting at the specified index.
  1747      *
  1748      * <p>The returned index is the smallest value <i>k</i> for which:
  1749      * <blockquote><pre>
  1750      * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
  1751      * </pre></blockquote>
  1752      * If no such value of <i>k</i> exists, then {@code -1} is returned.
  1753      *
  1754      * @param   str         the substring to search for.
  1755      * @param   fromIndex   the index from which to start the search.
  1756      * @return  the index of the first occurrence of the specified substring,
  1757      *          starting at the specified index,
  1758      *          or {@code -1} if there is no such occurrence.
  1759      */
  1760     public int indexOf(String str, int fromIndex) {
  1761         return indexOf(value, offset, count,
  1762                        str.value, str.offset, str.count, fromIndex);
  1763     }
  1764 
  1765     /**
  1766      * Code shared by String and StringBuffer to do searches. The
  1767      * source is the character array being searched, and the target
  1768      * is the string being searched for.
  1769      *
  1770      * @param   source       the characters being searched.
  1771      * @param   sourceOffset offset of the source string.
  1772      * @param   sourceCount  count of the source string.
  1773      * @param   target       the characters being searched for.
  1774      * @param   targetOffset offset of the target string.
  1775      * @param   targetCount  count of the target string.
  1776      * @param   fromIndex    the index to begin searching from.
  1777      */
  1778     static int indexOf(char[] source, int sourceOffset, int sourceCount,
  1779                        char[] target, int targetOffset, int targetCount,
  1780                        int fromIndex) {
  1781         if (fromIndex >= sourceCount) {
  1782             return (targetCount == 0 ? sourceCount : -1);
  1783         }
  1784         if (fromIndex < 0) {
  1785             fromIndex = 0;
  1786         }
  1787         if (targetCount == 0) {
  1788             return fromIndex;
  1789         }
  1790 
  1791         char first  = target[targetOffset];
  1792         int max = sourceOffset + (sourceCount - targetCount);
  1793 
  1794         for (int i = sourceOffset + fromIndex; i <= max; i++) {
  1795             /* Look for first character. */
  1796             if (source[i] != first) {
  1797                 while (++i <= max && source[i] != first);
  1798             }
  1799 
  1800             /* Found first character, now look at the rest of v2 */
  1801             if (i <= max) {
  1802                 int j = i + 1;
  1803                 int end = j + targetCount - 1;
  1804                 for (int k = targetOffset + 1; j < end && source[j] ==
  1805                          target[k]; j++, k++);
  1806 
  1807                 if (j == end) {
  1808                     /* Found whole string. */
  1809                     return i - sourceOffset;
  1810                 }
  1811             }
  1812         }
  1813         return -1;
  1814     }
  1815 
  1816     /**
  1817      * Returns the index within this string of the last occurrence of the
  1818      * specified substring.  The last occurrence of the empty string ""
  1819      * is considered to occur at the index value {@code this.length()}.
  1820      *
  1821      * <p>The returned index is the largest value <i>k</i> for which:
  1822      * <blockquote><pre>
  1823      * this.startsWith(str, <i>k</i>)
  1824      * </pre></blockquote>
  1825      * If no such value of <i>k</i> exists, then {@code -1} is returned.
  1826      *
  1827      * @param   str   the substring to search for.
  1828      * @return  the index of the last occurrence of the specified substring,
  1829      *          or {@code -1} if there is no such occurrence.
  1830      */
  1831     public int lastIndexOf(String str) {
  1832         return lastIndexOf(str, count);
  1833     }
  1834 
  1835     /**
  1836      * Returns the index within this string of the last occurrence of the
  1837      * specified substring, searching backward starting at the specified index.
  1838      *
  1839      * <p>The returned index is the largest value <i>k</i> for which:
  1840      * <blockquote><pre>
  1841      * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
  1842      * </pre></blockquote>
  1843      * If no such value of <i>k</i> exists, then {@code -1} is returned.
  1844      *
  1845      * @param   str         the substring to search for.
  1846      * @param   fromIndex   the index to start the search from.
  1847      * @return  the index of the last occurrence of the specified substring,
  1848      *          searching backward from the specified index,
  1849      *          or {@code -1} if there is no such occurrence.
  1850      */
  1851     public int lastIndexOf(String str, int fromIndex) {
  1852         return lastIndexOf(value, offset, count,
  1853                            str.value, str.offset, str.count, fromIndex);
  1854     }
  1855 
  1856     /**
  1857      * Code shared by String and StringBuffer to do searches. The
  1858      * source is the character array being searched, and the target
  1859      * is the string being searched for.
  1860      *
  1861      * @param   source       the characters being searched.
  1862      * @param   sourceOffset offset of the source string.
  1863      * @param   sourceCount  count of the source string.
  1864      * @param   target       the characters being searched for.
  1865      * @param   targetOffset offset of the target string.
  1866      * @param   targetCount  count of the target string.
  1867      * @param   fromIndex    the index to begin searching from.
  1868      */
  1869     static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
  1870                            char[] target, int targetOffset, int targetCount,
  1871                            int fromIndex) {
  1872         /*
  1873          * Check arguments; return immediately where possible. For
  1874          * consistency, don't check for null str.
  1875          */
  1876         int rightIndex = sourceCount - targetCount;
  1877         if (fromIndex < 0) {
  1878             return -1;
  1879         }
  1880         if (fromIndex > rightIndex) {
  1881             fromIndex = rightIndex;
  1882         }
  1883         /* Empty string always matches. */
  1884         if (targetCount == 0) {
  1885             return fromIndex;
  1886         }
  1887 
  1888         int strLastIndex = targetOffset + targetCount - 1;
  1889         char strLastChar = target[strLastIndex];
  1890         int min = sourceOffset + targetCount - 1;
  1891         int i = min + fromIndex;
  1892 
  1893     startSearchForLastChar:
  1894         while (true) {
  1895             while (i >= min && source[i] != strLastChar) {
  1896                 i--;
  1897             }
  1898             if (i < min) {
  1899                 return -1;
  1900             }
  1901             int j = i - 1;
  1902             int start = j - (targetCount - 1);
  1903             int k = strLastIndex - 1;
  1904 
  1905             while (j > start) {
  1906                 if (source[j--] != target[k--]) {
  1907                     i--;
  1908                     continue startSearchForLastChar;
  1909                 }
  1910             }
  1911             return start - sourceOffset + 1;
  1912         }
  1913     }
  1914 
  1915     /**
  1916      * Returns a new string that is a substring of this string. The
  1917      * substring begins with the character at the specified index and
  1918      * extends to the end of this string. <p>
  1919      * Examples:
  1920      * <blockquote><pre>
  1921      * "unhappy".substring(2) returns "happy"
  1922      * "Harbison".substring(3) returns "bison"
  1923      * "emptiness".substring(9) returns "" (an empty string)
  1924      * </pre></blockquote>
  1925      *
  1926      * @param      beginIndex   the beginning index, inclusive.
  1927      * @return     the specified substring.
  1928      * @exception  IndexOutOfBoundsException  if
  1929      *             <code>beginIndex</code> is negative or larger than the
  1930      *             length of this <code>String</code> object.
  1931      */
  1932     public String substring(int beginIndex) {
  1933         return substring(beginIndex, count);
  1934     }
  1935 
  1936     /**
  1937      * Returns a new string that is a substring of this string. The
  1938      * substring begins at the specified <code>beginIndex</code> and
  1939      * extends to the character at index <code>endIndex - 1</code>.
  1940      * Thus the length of the substring is <code>endIndex-beginIndex</code>.
  1941      * <p>
  1942      * Examples:
  1943      * <blockquote><pre>
  1944      * "hamburger".substring(4, 8) returns "urge"
  1945      * "smiles".substring(1, 5) returns "mile"
  1946      * </pre></blockquote>
  1947      *
  1948      * @param      beginIndex   the beginning index, inclusive.
  1949      * @param      endIndex     the ending index, exclusive.
  1950      * @return     the specified substring.
  1951      * @exception  IndexOutOfBoundsException  if the
  1952      *             <code>beginIndex</code> is negative, or
  1953      *             <code>endIndex</code> is larger than the length of
  1954      *             this <code>String</code> object, or
  1955      *             <code>beginIndex</code> is larger than
  1956      *             <code>endIndex</code>.
  1957      */
  1958     public String substring(int beginIndex, int endIndex) {
  1959         if (beginIndex < 0) {
  1960             throw new StringIndexOutOfBoundsException(beginIndex);
  1961         }
  1962         if (endIndex > count) {
  1963             throw new StringIndexOutOfBoundsException(endIndex);
  1964         }
  1965         if (beginIndex > endIndex) {
  1966             throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
  1967         }
  1968         return ((beginIndex == 0) && (endIndex == count)) ? this :
  1969             new String(offset + beginIndex, endIndex - beginIndex, value);
  1970     }
  1971 
  1972     /**
  1973      * Returns a new character sequence that is a subsequence of this sequence.
  1974      *
  1975      * <p> An invocation of this method of the form
  1976      *
  1977      * <blockquote><pre>
  1978      * str.subSequence(begin,&nbsp;end)</pre></blockquote>
  1979      *
  1980      * behaves in exactly the same way as the invocation
  1981      *
  1982      * <blockquote><pre>
  1983      * str.substring(begin,&nbsp;end)</pre></blockquote>
  1984      *
  1985      * This method is defined so that the <tt>String</tt> class can implement
  1986      * the {@link CharSequence} interface. </p>
  1987      *
  1988      * @param      beginIndex   the begin index, inclusive.
  1989      * @param      endIndex     the end index, exclusive.
  1990      * @return     the specified subsequence.
  1991      *
  1992      * @throws  IndexOutOfBoundsException
  1993      *          if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
  1994      *          if <tt>endIndex</tt> is greater than <tt>length()</tt>,
  1995      *          or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
  1996      *
  1997      * @since 1.4
  1998      * @spec JSR-51
  1999      */
  2000     public CharSequence subSequence(int beginIndex, int endIndex) {
  2001         return this.substring(beginIndex, endIndex);
  2002     }
  2003 
  2004     /**
  2005      * Concatenates the specified string to the end of this string.
  2006      * <p>
  2007      * If the length of the argument string is <code>0</code>, then this
  2008      * <code>String</code> object is returned. Otherwise, a new
  2009      * <code>String</code> object is created, representing a character
  2010      * sequence that is the concatenation of the character sequence
  2011      * represented by this <code>String</code> object and the character
  2012      * sequence represented by the argument string.<p>
  2013      * Examples:
  2014      * <blockquote><pre>
  2015      * "cares".concat("s") returns "caress"
  2016      * "to".concat("get").concat("her") returns "together"
  2017      * </pre></blockquote>
  2018      *
  2019      * @param   str   the <code>String</code> that is concatenated to the end
  2020      *                of this <code>String</code>.
  2021      * @return  a string that represents the concatenation of this object's
  2022      *          characters followed by the string argument's characters.
  2023      */
  2024     public String concat(String str) {
  2025         int otherLen = str.length();
  2026         if (otherLen == 0) {
  2027             return this;
  2028         }
  2029         char buf[] = new char[count + otherLen];
  2030         getChars(0, count, buf, 0);
  2031         str.getChars(0, otherLen, buf, count);
  2032         return new String(0, count + otherLen, buf);
  2033     }
  2034 
  2035     /**
  2036      * Returns a new string resulting from replacing all occurrences of
  2037      * <code>oldChar</code> in this string with <code>newChar</code>.
  2038      * <p>
  2039      * If the character <code>oldChar</code> does not occur in the
  2040      * character sequence represented by this <code>String</code> object,
  2041      * then a reference to this <code>String</code> object is returned.
  2042      * Otherwise, a new <code>String</code> object is created that
  2043      * represents a character sequence identical to the character sequence
  2044      * represented by this <code>String</code> object, except that every
  2045      * occurrence of <code>oldChar</code> is replaced by an occurrence
  2046      * of <code>newChar</code>.
  2047      * <p>
  2048      * Examples:
  2049      * <blockquote><pre>
  2050      * "mesquite in your cellar".replace('e', 'o')
  2051      *         returns "mosquito in your collar"
  2052      * "the war of baronets".replace('r', 'y')
  2053      *         returns "the way of bayonets"
  2054      * "sparring with a purple porpoise".replace('p', 't')
  2055      *         returns "starring with a turtle tortoise"
  2056      * "JonL".replace('q', 'x') returns "JonL" (no change)
  2057      * </pre></blockquote>
  2058      *
  2059      * @param   oldChar   the old character.
  2060      * @param   newChar   the new character.
  2061      * @return  a string derived from this string by replacing every
  2062      *          occurrence of <code>oldChar</code> with <code>newChar</code>.
  2063      */
  2064     public String replace(char oldChar, char newChar) {
  2065         if (oldChar != newChar) {
  2066             int len = count;
  2067             int i = -1;
  2068             char[] val = value; /* avoid getfield opcode */
  2069             int off = offset;   /* avoid getfield opcode */
  2070 
  2071             while (++i < len) {
  2072                 if (val[off + i] == oldChar) {
  2073                     break;
  2074                 }
  2075             }
  2076             if (i < len) {
  2077                 char buf[] = new char[len];
  2078                 for (int j = 0 ; j < i ; j++) {
  2079                     buf[j] = val[off+j];
  2080                 }
  2081                 while (i < len) {
  2082                     char c = val[off + i];
  2083                     buf[i] = (c == oldChar) ? newChar : c;
  2084                     i++;
  2085                 }
  2086                 return new String(0, len, buf);
  2087             }
  2088         }
  2089         return this;
  2090     }
  2091 
  2092     /**
  2093      * Tells whether or not this string matches the given <a
  2094      * href="../util/regex/Pattern.html#sum">regular expression</a>.
  2095      *
  2096      * <p> An invocation of this method of the form
  2097      * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
  2098      * same result as the expression
  2099      *
  2100      * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
  2101      * java.util.regex.Pattern#matches(String,CharSequence)
  2102      * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
  2103      *
  2104      * @param   regex
  2105      *          the regular expression to which this string is to be matched
  2106      *
  2107      * @return  <tt>true</tt> if, and only if, this string matches the
  2108      *          given regular expression
  2109      *
  2110      * @throws  PatternSyntaxException
  2111      *          if the regular expression's syntax is invalid
  2112      *
  2113      * @see java.util.regex.Pattern
  2114      *
  2115      * @since 1.4
  2116      * @spec JSR-51
  2117      */
  2118     public boolean matches(String regex) {
  2119         throw new UnsupportedOperationException();
  2120     }
  2121 
  2122     /**
  2123      * Returns true if and only if this string contains the specified
  2124      * sequence of char values.
  2125      *
  2126      * @param s the sequence to search for
  2127      * @return true if this string contains <code>s</code>, false otherwise
  2128      * @throws NullPointerException if <code>s</code> is <code>null</code>
  2129      * @since 1.5
  2130      */
  2131     public boolean contains(CharSequence s) {
  2132         return indexOf(s.toString()) > -1;
  2133     }
  2134 
  2135     /**
  2136      * Replaces the first substring of this string that matches the given <a
  2137      * href="../util/regex/Pattern.html#sum">regular expression</a> with the
  2138      * given replacement.
  2139      *
  2140      * <p> An invocation of this method of the form
  2141      * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
  2142      * yields exactly the same result as the expression
  2143      *
  2144      * <blockquote><tt>
  2145      * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
  2146      * compile}(</tt><i>regex</i><tt>).{@link
  2147      * java.util.regex.Pattern#matcher(java.lang.CharSequence)
  2148      * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
  2149      * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
  2150      *
  2151      *<p>
  2152      * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
  2153      * replacement string may cause the results to be different than if it were
  2154      * being treated as a literal replacement string; see
  2155      * {@link java.util.regex.Matcher#replaceFirst}.
  2156      * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
  2157      * meaning of these characters, if desired.
  2158      *
  2159      * @param   regex
  2160      *          the regular expression to which this string is to be matched
  2161      * @param   replacement
  2162      *          the string to be substituted for the first match
  2163      *
  2164      * @return  The resulting <tt>String</tt>
  2165      *
  2166      * @throws  PatternSyntaxException
  2167      *          if the regular expression's syntax is invalid
  2168      *
  2169      * @see java.util.regex.Pattern
  2170      *
  2171      * @since 1.4
  2172      * @spec JSR-51
  2173      */
  2174     public String replaceFirst(String regex, String replacement) {
  2175         throw new UnsupportedOperationException();
  2176     }
  2177 
  2178     /**
  2179      * Replaces each substring of this string that matches the given <a
  2180      * href="../util/regex/Pattern.html#sum">regular expression</a> with the
  2181      * given replacement.
  2182      *
  2183      * <p> An invocation of this method of the form
  2184      * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
  2185      * yields exactly the same result as the expression
  2186      *
  2187      * <blockquote><tt>
  2188      * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
  2189      * compile}(</tt><i>regex</i><tt>).{@link
  2190      * java.util.regex.Pattern#matcher(java.lang.CharSequence)
  2191      * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
  2192      * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
  2193      *
  2194      *<p>
  2195      * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
  2196      * replacement string may cause the results to be different than if it were
  2197      * being treated as a literal replacement string; see
  2198      * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
  2199      * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
  2200      * meaning of these characters, if desired.
  2201      *
  2202      * @param   regex
  2203      *          the regular expression to which this string is to be matched
  2204      * @param   replacement
  2205      *          the string to be substituted for each match
  2206      *
  2207      * @return  The resulting <tt>String</tt>
  2208      *
  2209      * @throws  PatternSyntaxException
  2210      *          if the regular expression's syntax is invalid
  2211      *
  2212      * @see java.util.regex.Pattern
  2213      *
  2214      * @since 1.4
  2215      * @spec JSR-51
  2216      */
  2217     public String replaceAll(String regex, String replacement) {
  2218         throw new UnsupportedOperationException();
  2219     }
  2220 
  2221     /**
  2222      * Replaces each substring of this string that matches the literal target
  2223      * sequence with the specified literal replacement sequence. The
  2224      * replacement proceeds from the beginning of the string to the end, for
  2225      * example, replacing "aa" with "b" in the string "aaa" will result in
  2226      * "ba" rather than "ab".
  2227      *
  2228      * @param  target The sequence of char values to be replaced
  2229      * @param  replacement The replacement sequence of char values
  2230      * @return  The resulting string
  2231      * @throws NullPointerException if <code>target</code> or
  2232      *         <code>replacement</code> is <code>null</code>.
  2233      * @since 1.5
  2234      */
  2235     public String replace(CharSequence target, CharSequence replacement) {
  2236         throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
  2237     }
  2238 
  2239     /**
  2240      * Splits this string around matches of the given
  2241      * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
  2242      *
  2243      * <p> The array returned by this method contains each substring of this
  2244      * string that is terminated by another substring that matches the given
  2245      * expression or is terminated by the end of the string.  The substrings in
  2246      * the array are in the order in which they occur in this string.  If the
  2247      * expression does not match any part of the input then the resulting array
  2248      * has just one element, namely this string.
  2249      *
  2250      * <p> The <tt>limit</tt> parameter controls the number of times the
  2251      * pattern is applied and therefore affects the length of the resulting
  2252      * array.  If the limit <i>n</i> is greater than zero then the pattern
  2253      * will be applied at most <i>n</i>&nbsp;-&nbsp;1 times, the array's
  2254      * length will be no greater than <i>n</i>, and the array's last entry
  2255      * will contain all input beyond the last matched delimiter.  If <i>n</i>
  2256      * is non-positive then the pattern will be applied as many times as
  2257      * possible and the array can have any length.  If <i>n</i> is zero then
  2258      * the pattern will be applied as many times as possible, the array can
  2259      * have any length, and trailing empty strings will be discarded.
  2260      *
  2261      * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
  2262      * following results with these parameters:
  2263      *
  2264      * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
  2265      * <tr>
  2266      *     <th>Regex</th>
  2267      *     <th>Limit</th>
  2268      *     <th>Result</th>
  2269      * </tr>
  2270      * <tr><td align=center>:</td>
  2271      *     <td align=center>2</td>
  2272      *     <td><tt>{ "boo", "and:foo" }</tt></td></tr>
  2273      * <tr><td align=center>:</td>
  2274      *     <td align=center>5</td>
  2275      *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
  2276      * <tr><td align=center>:</td>
  2277      *     <td align=center>-2</td>
  2278      *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
  2279      * <tr><td align=center>o</td>
  2280      *     <td align=center>5</td>
  2281      *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
  2282      * <tr><td align=center>o</td>
  2283      *     <td align=center>-2</td>
  2284      *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
  2285      * <tr><td align=center>o</td>
  2286      *     <td align=center>0</td>
  2287      *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
  2288      * </table></blockquote>
  2289      *
  2290      * <p> An invocation of this method of the form
  2291      * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
  2292      * yields the same result as the expression
  2293      *
  2294      * <blockquote>
  2295      * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
  2296      * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
  2297      * java.util.regex.Pattern#split(java.lang.CharSequence,int)
  2298      * split}<tt>(</tt><i>str</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
  2299      * </blockquote>
  2300      *
  2301      *
  2302      * @param  regex
  2303      *         the delimiting regular expression
  2304      *
  2305      * @param  limit
  2306      *         the result threshold, as described above
  2307      *
  2308      * @return  the array of strings computed by splitting this string
  2309      *          around matches of the given regular expression
  2310      *
  2311      * @throws  PatternSyntaxException
  2312      *          if the regular expression's syntax is invalid
  2313      *
  2314      * @see java.util.regex.Pattern
  2315      *
  2316      * @since 1.4
  2317      * @spec JSR-51
  2318      */
  2319     public String[] split(String regex, int limit) {
  2320         throw new UnsupportedOperationException("Needs regexp");
  2321     }
  2322 
  2323     /**
  2324      * Splits this string around matches of the given <a
  2325      * href="../util/regex/Pattern.html#sum">regular expression</a>.
  2326      *
  2327      * <p> This method works as if by invoking the two-argument {@link
  2328      * #split(String, int) split} method with the given expression and a limit
  2329      * argument of zero.  Trailing empty strings are therefore not included in
  2330      * the resulting array.
  2331      *
  2332      * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
  2333      * results with these expressions:
  2334      *
  2335      * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
  2336      * <tr>
  2337      *  <th>Regex</th>
  2338      *  <th>Result</th>
  2339      * </tr>
  2340      * <tr><td align=center>:</td>
  2341      *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
  2342      * <tr><td align=center>o</td>
  2343      *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
  2344      * </table></blockquote>
  2345      *
  2346      *
  2347      * @param  regex
  2348      *         the delimiting regular expression
  2349      *
  2350      * @return  the array of strings computed by splitting this string
  2351      *          around matches of the given regular expression
  2352      *
  2353      * @throws  PatternSyntaxException
  2354      *          if the regular expression's syntax is invalid
  2355      *
  2356      * @see java.util.regex.Pattern
  2357      *
  2358      * @since 1.4
  2359      * @spec JSR-51
  2360      */
  2361     public String[] split(String regex) {
  2362         return split(regex, 0);
  2363     }
  2364 
  2365     /**
  2366      * Converts all of the characters in this <code>String</code> to lower
  2367      * case using the rules of the given <code>Locale</code>.  Case mapping is based
  2368      * on the Unicode Standard version specified by the {@link java.lang.Character Character}
  2369      * class. Since case mappings are not always 1:1 char mappings, the resulting
  2370      * <code>String</code> may be a different length than the original <code>String</code>.
  2371      * <p>
  2372      * Examples of lowercase  mappings are in the following table:
  2373      * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
  2374      * <tr>
  2375      *   <th>Language Code of Locale</th>
  2376      *   <th>Upper Case</th>
  2377      *   <th>Lower Case</th>
  2378      *   <th>Description</th>
  2379      * </tr>
  2380      * <tr>
  2381      *   <td>tr (Turkish)</td>
  2382      *   <td>&#92;u0130</td>
  2383      *   <td>&#92;u0069</td>
  2384      *   <td>capital letter I with dot above -&gt; small letter i</td>
  2385      * </tr>
  2386      * <tr>
  2387      *   <td>tr (Turkish)</td>
  2388      *   <td>&#92;u0049</td>
  2389      *   <td>&#92;u0131</td>
  2390      *   <td>capital letter I -&gt; small letter dotless i </td>
  2391      * </tr>
  2392      * <tr>
  2393      *   <td>(all)</td>
  2394      *   <td>French Fries</td>
  2395      *   <td>french fries</td>
  2396      *   <td>lowercased all chars in String</td>
  2397      * </tr>
  2398      * <tr>
  2399      *   <td>(all)</td>
  2400      *   <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
  2401      *       <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
  2402      *       <img src="doc-files/capsigma.gif" alt="capsigma"></td>
  2403      *   <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
  2404      *       <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
  2405      *       <img src="doc-files/sigma1.gif" alt="sigma"></td>
  2406      *   <td>lowercased all chars in String</td>
  2407      * </tr>
  2408      * </table>
  2409      *
  2410      * @param locale use the case transformation rules for this locale
  2411      * @return the <code>String</code>, converted to lowercase.
  2412      * @see     java.lang.String#toLowerCase()
  2413      * @see     java.lang.String#toUpperCase()
  2414      * @see     java.lang.String#toUpperCase(Locale)
  2415      * @since   1.1
  2416      */
  2417 //    public String toLowerCase(Locale locale) {
  2418 //        if (locale == null) {
  2419 //            throw new NullPointerException();
  2420 //        }
  2421 //
  2422 //        int     firstUpper;
  2423 //
  2424 //        /* Now check if there are any characters that need to be changed. */
  2425 //        scan: {
  2426 //            for (firstUpper = 0 ; firstUpper < count; ) {
  2427 //                char c = value[offset+firstUpper];
  2428 //                if ((c >= Character.MIN_HIGH_SURROGATE) &&
  2429 //                    (c <= Character.MAX_HIGH_SURROGATE)) {
  2430 //                    int supplChar = codePointAt(firstUpper);
  2431 //                    if (supplChar != Character.toLowerCase(supplChar)) {
  2432 //                        break scan;
  2433 //                    }
  2434 //                    firstUpper += Character.charCount(supplChar);
  2435 //                } else {
  2436 //                    if (c != Character.toLowerCase(c)) {
  2437 //                        break scan;
  2438 //                    }
  2439 //                    firstUpper++;
  2440 //                }
  2441 //            }
  2442 //            return this;
  2443 //        }
  2444 //
  2445 //        char[]  result = new char[count];
  2446 //        int     resultOffset = 0;  /* result may grow, so i+resultOffset
  2447 //                                    * is the write location in result */
  2448 //
  2449 //        /* Just copy the first few lowerCase characters. */
  2450 //        arraycopy(value, offset, result, 0, firstUpper);
  2451 //
  2452 //        String lang = locale.getLanguage();
  2453 //        boolean localeDependent =
  2454 //            (lang == "tr" || lang == "az" || lang == "lt");
  2455 //        char[] lowerCharArray;
  2456 //        int lowerChar;
  2457 //        int srcChar;
  2458 //        int srcCount;
  2459 //        for (int i = firstUpper; i < count; i += srcCount) {
  2460 //            srcChar = (int)value[offset+i];
  2461 //            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
  2462 //                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
  2463 //                srcChar = codePointAt(i);
  2464 //                srcCount = Character.charCount(srcChar);
  2465 //            } else {
  2466 //                srcCount = 1;
  2467 //            }
  2468 //            if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
  2469 //                lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
  2470 //            } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
  2471 //                lowerChar = Character.ERROR;
  2472 //            } else {
  2473 //                lowerChar = Character.toLowerCase(srcChar);
  2474 //            }
  2475 //            if ((lowerChar == Character.ERROR) ||
  2476 //                (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
  2477 //                if (lowerChar == Character.ERROR) {
  2478 //                     if (!localeDependent && srcChar == '\u0130') {
  2479 //                         lowerCharArray =
  2480 //                             ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
  2481 //                     } else {
  2482 //                        lowerCharArray =
  2483 //                            ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
  2484 //                     }
  2485 //                } else if (srcCount == 2) {
  2486 //                    resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
  2487 //                    continue;
  2488 //                } else {
  2489 //                    lowerCharArray = Character.toChars(lowerChar);
  2490 //                }
  2491 //
  2492 //                /* Grow result if needed */
  2493 //                int mapLen = lowerCharArray.length;
  2494 //                if (mapLen > srcCount) {
  2495 //                    char[] result2 = new char[result.length + mapLen - srcCount];
  2496 //                    arraycopy(result, 0, result2, 0,
  2497 //                        i + resultOffset);
  2498 //                    result = result2;
  2499 //                }
  2500 //                for (int x=0; x<mapLen; ++x) {
  2501 //                    result[i+resultOffset+x] = lowerCharArray[x];
  2502 //                }
  2503 //                resultOffset += (mapLen - srcCount);
  2504 //            } else {
  2505 //                result[i+resultOffset] = (char)lowerChar;
  2506 //            }
  2507 //        }
  2508 //        return new String(0, count+resultOffset, result);
  2509 //    }
  2510 
  2511     /**
  2512      * Converts all of the characters in this <code>String</code> to lower
  2513      * case using the rules of the default locale. This is equivalent to calling
  2514      * <code>toLowerCase(Locale.getDefault())</code>.
  2515      * <p>
  2516      * <b>Note:</b> This method is locale sensitive, and may produce unexpected
  2517      * results if used for strings that are intended to be interpreted locale
  2518      * independently.
  2519      * Examples are programming language identifiers, protocol keys, and HTML
  2520      * tags.
  2521      * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
  2522      * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
  2523      * LATIN SMALL LETTER DOTLESS I character.
  2524      * To obtain correct results for locale insensitive strings, use
  2525      * <code>toLowerCase(Locale.ENGLISH)</code>.
  2526      * <p>
  2527      * @return  the <code>String</code>, converted to lowercase.
  2528      * @see     java.lang.String#toLowerCase(Locale)
  2529      */
  2530     public String toLowerCase() {
  2531         throw new UnsupportedOperationException("Should be supported but without connection to locale");
  2532     }
  2533 
  2534     /**
  2535      * Converts all of the characters in this <code>String</code> to upper
  2536      * case using the rules of the given <code>Locale</code>. Case mapping is based
  2537      * on the Unicode Standard version specified by the {@link java.lang.Character Character}
  2538      * class. Since case mappings are not always 1:1 char mappings, the resulting
  2539      * <code>String</code> may be a different length than the original <code>String</code>.
  2540      * <p>
  2541      * Examples of locale-sensitive and 1:M case mappings are in the following table.
  2542      * <p>
  2543      * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
  2544      * <tr>
  2545      *   <th>Language Code of Locale</th>
  2546      *   <th>Lower Case</th>
  2547      *   <th>Upper Case</th>
  2548      *   <th>Description</th>
  2549      * </tr>
  2550      * <tr>
  2551      *   <td>tr (Turkish)</td>
  2552      *   <td>&#92;u0069</td>
  2553      *   <td>&#92;u0130</td>
  2554      *   <td>small letter i -&gt; capital letter I with dot above</td>
  2555      * </tr>
  2556      * <tr>
  2557      *   <td>tr (Turkish)</td>
  2558      *   <td>&#92;u0131</td>
  2559      *   <td>&#92;u0049</td>
  2560      *   <td>small letter dotless i -&gt; capital letter I</td>
  2561      * </tr>
  2562      * <tr>
  2563      *   <td>(all)</td>
  2564      *   <td>&#92;u00df</td>
  2565      *   <td>&#92;u0053 &#92;u0053</td>
  2566      *   <td>small letter sharp s -&gt; two letters: SS</td>
  2567      * </tr>
  2568      * <tr>
  2569      *   <td>(all)</td>
  2570      *   <td>Fahrvergn&uuml;gen</td>
  2571      *   <td>FAHRVERGN&Uuml;GEN</td>
  2572      *   <td></td>
  2573      * </tr>
  2574      * </table>
  2575      * @param locale use the case transformation rules for this locale
  2576      * @return the <code>String</code>, converted to uppercase.
  2577      * @see     java.lang.String#toUpperCase()
  2578      * @see     java.lang.String#toLowerCase()
  2579      * @see     java.lang.String#toLowerCase(Locale)
  2580      * @since   1.1
  2581      */
  2582     /* not for javascript 
  2583     public String toUpperCase(Locale locale) {
  2584         if (locale == null) {
  2585             throw new NullPointerException();
  2586         }
  2587 
  2588         int     firstLower;
  2589 
  2590         // Now check if there are any characters that need to be changed. 
  2591         scan: {
  2592             for (firstLower = 0 ; firstLower < count; ) {
  2593                 int c = (int)value[offset+firstLower];
  2594                 int srcCount;
  2595                 if ((c >= Character.MIN_HIGH_SURROGATE) &&
  2596                     (c <= Character.MAX_HIGH_SURROGATE)) {
  2597                     c = codePointAt(firstLower);
  2598                     srcCount = Character.charCount(c);
  2599                 } else {
  2600                     srcCount = 1;
  2601                 }
  2602                 int upperCaseChar = Character.toUpperCaseEx(c);
  2603                 if ((upperCaseChar == Character.ERROR) ||
  2604                     (c != upperCaseChar)) {
  2605                     break scan;
  2606                 }
  2607                 firstLower += srcCount;
  2608             }
  2609             return this;
  2610         }
  2611 
  2612         char[]  result       = new char[count]; /* may grow *
  2613         int     resultOffset = 0;  /* result may grow, so i+resultOffset
  2614                                     * is the write location in result *
  2615 
  2616         /* Just copy the first few upperCase characters. *
  2617         arraycopy(value, offset, result, 0, firstLower);
  2618 
  2619         String lang = locale.getLanguage();
  2620         boolean localeDependent =
  2621             (lang == "tr" || lang == "az" || lang == "lt");
  2622         char[] upperCharArray;
  2623         int upperChar;
  2624         int srcChar;
  2625         int srcCount;
  2626         for (int i = firstLower; i < count; i += srcCount) {
  2627             srcChar = (int)value[offset+i];
  2628             if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
  2629                 (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
  2630                 srcChar = codePointAt(i);
  2631                 srcCount = Character.charCount(srcChar);
  2632             } else {
  2633                 srcCount = 1;
  2634             }
  2635             if (localeDependent) {
  2636                 upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
  2637             } else {
  2638                 upperChar = Character.toUpperCaseEx(srcChar);
  2639             }
  2640             if ((upperChar == Character.ERROR) ||
  2641                 (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
  2642                 if (upperChar == Character.ERROR) {
  2643                     if (localeDependent) {
  2644                         upperCharArray =
  2645                             ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
  2646                     } else {
  2647                         upperCharArray = Character.toUpperCaseCharArray(srcChar);
  2648                     }
  2649                 } else if (srcCount == 2) {
  2650                     resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
  2651                     continue;
  2652                 } else {
  2653                     upperCharArray = Character.toChars(upperChar);
  2654                 }
  2655 
  2656                 /* Grow result if needed *
  2657                 int mapLen = upperCharArray.length;
  2658                 if (mapLen > srcCount) {
  2659                     char[] result2 = new char[result.length + mapLen - srcCount];
  2660                     arraycopy(result, 0, result2, 0,
  2661                         i + resultOffset);
  2662                     result = result2;
  2663                 }
  2664                 for (int x=0; x<mapLen; ++x) {
  2665                     result[i+resultOffset+x] = upperCharArray[x];
  2666                 }
  2667                 resultOffset += (mapLen - srcCount);
  2668             } else {
  2669                 result[i+resultOffset] = (char)upperChar;
  2670             }
  2671         }
  2672         return new String(0, count+resultOffset, result);
  2673     }
  2674     */
  2675 
  2676     /**
  2677      * Converts all of the characters in this <code>String</code> to upper
  2678      * case using the rules of the default locale. This method is equivalent to
  2679      * <code>toUpperCase(Locale.getDefault())</code>.
  2680      * <p>
  2681      * <b>Note:</b> This method is locale sensitive, and may produce unexpected
  2682      * results if used for strings that are intended to be interpreted locale
  2683      * independently.
  2684      * Examples are programming language identifiers, protocol keys, and HTML
  2685      * tags.
  2686      * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
  2687      * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
  2688      * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
  2689      * To obtain correct results for locale insensitive strings, use
  2690      * <code>toUpperCase(Locale.ENGLISH)</code>.
  2691      * <p>
  2692      * @return  the <code>String</code>, converted to uppercase.
  2693      * @see     java.lang.String#toUpperCase(Locale)
  2694      */
  2695     public String toUpperCase() {
  2696         throw new UnsupportedOperationException();
  2697     }
  2698 
  2699     /**
  2700      * Returns a copy of the string, with leading and trailing whitespace
  2701      * omitted.
  2702      * <p>
  2703      * If this <code>String</code> object represents an empty character
  2704      * sequence, or the first and last characters of character sequence
  2705      * represented by this <code>String</code> object both have codes
  2706      * greater than <code>'&#92;u0020'</code> (the space character), then a
  2707      * reference to this <code>String</code> object is returned.
  2708      * <p>
  2709      * Otherwise, if there is no character with a code greater than
  2710      * <code>'&#92;u0020'</code> in the string, then a new
  2711      * <code>String</code> object representing an empty string is created
  2712      * and returned.
  2713      * <p>
  2714      * Otherwise, let <i>k</i> be the index of the first character in the
  2715      * string whose code is greater than <code>'&#92;u0020'</code>, and let
  2716      * <i>m</i> be the index of the last character in the string whose code
  2717      * is greater than <code>'&#92;u0020'</code>. A new <code>String</code>
  2718      * object is created, representing the substring of this string that
  2719      * begins with the character at index <i>k</i> and ends with the
  2720      * character at index <i>m</i>-that is, the result of
  2721      * <code>this.substring(<i>k</i>,&nbsp;<i>m</i>+1)</code>.
  2722      * <p>
  2723      * This method may be used to trim whitespace (as defined above) from
  2724      * the beginning and end of a string.
  2725      *
  2726      * @return  A copy of this string with leading and trailing white
  2727      *          space removed, or this string if it has no leading or
  2728      *          trailing white space.
  2729      */
  2730     public String trim() {
  2731         int len = count;
  2732         int st = 0;
  2733         int off = offset;      /* avoid getfield opcode */
  2734         char[] val = value;    /* avoid getfield opcode */
  2735 
  2736         while ((st < len) && (val[off + st] <= ' ')) {
  2737             st++;
  2738         }
  2739         while ((st < len) && (val[off + len - 1] <= ' ')) {
  2740             len--;
  2741         }
  2742         return ((st > 0) || (len < count)) ? substring(st, len) : this;
  2743     }
  2744 
  2745     /**
  2746      * This object (which is already a string!) is itself returned.
  2747      *
  2748      * @return  the string itself.
  2749      */
  2750     public String toString() {
  2751         return this;
  2752     }
  2753 
  2754     /**
  2755      * Converts this string to a new character array.
  2756      *
  2757      * @return  a newly allocated character array whose length is the length
  2758      *          of this string and whose contents are initialized to contain
  2759      *          the character sequence represented by this string.
  2760      */
  2761     public char[] toCharArray() {
  2762         char result[] = new char[count];
  2763         getChars(0, count, result, 0);
  2764         return result;
  2765     }
  2766 
  2767     /**
  2768      * Returns a formatted string using the specified format string and
  2769      * arguments.
  2770      *
  2771      * <p> The locale always used is the one returned by {@link
  2772      * java.util.Locale#getDefault() Locale.getDefault()}.
  2773      *
  2774      * @param  format
  2775      *         A <a href="../util/Formatter.html#syntax">format string</a>
  2776      *
  2777      * @param  args
  2778      *         Arguments referenced by the format specifiers in the format
  2779      *         string.  If there are more arguments than format specifiers, the
  2780      *         extra arguments are ignored.  The number of arguments is
  2781      *         variable and may be zero.  The maximum number of arguments is
  2782      *         limited by the maximum dimension of a Java array as defined by
  2783      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
  2784      *         The behaviour on a
  2785      *         <tt>null</tt> argument depends on the <a
  2786      *         href="../util/Formatter.html#syntax">conversion</a>.
  2787      *
  2788      * @throws  IllegalFormatException
  2789      *          If a format string contains an illegal syntax, a format
  2790      *          specifier that is incompatible with the given arguments,
  2791      *          insufficient arguments given the format string, or other
  2792      *          illegal conditions.  For specification of all possible
  2793      *          formatting errors, see the <a
  2794      *          href="../util/Formatter.html#detail">Details</a> section of the
  2795      *          formatter class specification.
  2796      *
  2797      * @throws  NullPointerException
  2798      *          If the <tt>format</tt> is <tt>null</tt>
  2799      *
  2800      * @return  A formatted string
  2801      *
  2802      * @see  java.util.Formatter
  2803      * @since  1.5
  2804      */
  2805     public static String format(String format, Object ... args) {
  2806         throw new UnsupportedOperationException();
  2807     }
  2808 
  2809     /**
  2810      * Returns a formatted string using the specified locale, format string,
  2811      * and arguments.
  2812      *
  2813      * @param  l
  2814      *         The {@linkplain java.util.Locale locale} to apply during
  2815      *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
  2816      *         is applied.
  2817      *
  2818      * @param  format
  2819      *         A <a href="../util/Formatter.html#syntax">format string</a>
  2820      *
  2821      * @param  args
  2822      *         Arguments referenced by the format specifiers in the format
  2823      *         string.  If there are more arguments than format specifiers, the
  2824      *         extra arguments are ignored.  The number of arguments is
  2825      *         variable and may be zero.  The maximum number of arguments is
  2826      *         limited by the maximum dimension of a Java array as defined by
  2827      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
  2828      *         The behaviour on a
  2829      *         <tt>null</tt> argument depends on the <a
  2830      *         href="../util/Formatter.html#syntax">conversion</a>.
  2831      *
  2832      * @throws  IllegalFormatException
  2833      *          If a format string contains an illegal syntax, a format
  2834      *          specifier that is incompatible with the given arguments,
  2835      *          insufficient arguments given the format string, or other
  2836      *          illegal conditions.  For specification of all possible
  2837      *          formatting errors, see the <a
  2838      *          href="../util/Formatter.html#detail">Details</a> section of the
  2839      *          formatter class specification
  2840      *
  2841      * @throws  NullPointerException
  2842      *          If the <tt>format</tt> is <tt>null</tt>
  2843      *
  2844      * @return  A formatted string
  2845      *
  2846      * @see  java.util.Formatter
  2847      * @since  1.5
  2848      */
  2849 //    public static String format(Locale l, String format, Object ... args) {
  2850 //        return new Formatter(l).format(format, args).toString();
  2851 //    }
  2852 
  2853     /**
  2854      * Returns the string representation of the <code>Object</code> argument.
  2855      *
  2856      * @param   obj   an <code>Object</code>.
  2857      * @return  if the argument is <code>null</code>, then a string equal to
  2858      *          <code>"null"</code>; otherwise, the value of
  2859      *          <code>obj.toString()</code> is returned.
  2860      * @see     java.lang.Object#toString()
  2861      */
  2862     public static String valueOf(Object obj) {
  2863         return (obj == null) ? "null" : obj.toString();
  2864     }
  2865 
  2866     /**
  2867      * Returns the string representation of the <code>char</code> array
  2868      * argument. The contents of the character array are copied; subsequent
  2869      * modification of the character array does not affect the newly
  2870      * created string.
  2871      *
  2872      * @param   data   a <code>char</code> array.
  2873      * @return  a newly allocated string representing the same sequence of
  2874      *          characters contained in the character array argument.
  2875      */
  2876     public static String valueOf(char data[]) {
  2877         return new String(data);
  2878     }
  2879 
  2880     /**
  2881      * Returns the string representation of a specific subarray of the
  2882      * <code>char</code> array argument.
  2883      * <p>
  2884      * The <code>offset</code> argument is the index of the first
  2885      * character of the subarray. The <code>count</code> argument
  2886      * specifies the length of the subarray. The contents of the subarray
  2887      * are copied; subsequent modification of the character array does not
  2888      * affect the newly created string.
  2889      *
  2890      * @param   data     the character array.
  2891      * @param   offset   the initial offset into the value of the
  2892      *                  <code>String</code>.
  2893      * @param   count    the length of the value of the <code>String</code>.
  2894      * @return  a string representing the sequence of characters contained
  2895      *          in the subarray of the character array argument.
  2896      * @exception IndexOutOfBoundsException if <code>offset</code> is
  2897      *          negative, or <code>count</code> is negative, or
  2898      *          <code>offset+count</code> is larger than
  2899      *          <code>data.length</code>.
  2900      */
  2901     public static String valueOf(char data[], int offset, int count) {
  2902         return new String(data, offset, count);
  2903     }
  2904 
  2905     /**
  2906      * Returns a String that represents the character sequence in the
  2907      * array specified.
  2908      *
  2909      * @param   data     the character array.
  2910      * @param   offset   initial offset of the subarray.
  2911      * @param   count    length of the subarray.
  2912      * @return  a <code>String</code> that contains the characters of the
  2913      *          specified subarray of the character array.
  2914      */
  2915     public static String copyValueOf(char data[], int offset, int count) {
  2916         // All public String constructors now copy the data.
  2917         return new String(data, offset, count);
  2918     }
  2919 
  2920     /**
  2921      * Returns a String that represents the character sequence in the
  2922      * array specified.
  2923      *
  2924      * @param   data   the character array.
  2925      * @return  a <code>String</code> that contains the characters of the
  2926      *          character array.
  2927      */
  2928     public static String copyValueOf(char data[]) {
  2929         return copyValueOf(data, 0, data.length);
  2930     }
  2931 
  2932     /**
  2933      * Returns the string representation of the <code>boolean</code> argument.
  2934      *
  2935      * @param   b   a <code>boolean</code>.
  2936      * @return  if the argument is <code>true</code>, a string equal to
  2937      *          <code>"true"</code> is returned; otherwise, a string equal to
  2938      *          <code>"false"</code> is returned.
  2939      */
  2940     public static String valueOf(boolean b) {
  2941         return b ? "true" : "false";
  2942     }
  2943 
  2944     /**
  2945      * Returns the string representation of the <code>char</code>
  2946      * argument.
  2947      *
  2948      * @param   c   a <code>char</code>.
  2949      * @return  a string of length <code>1</code> containing
  2950      *          as its single character the argument <code>c</code>.
  2951      */
  2952     public static String valueOf(char c) {
  2953         char data[] = {c};
  2954         return new String(0, 1, data);
  2955     }
  2956 
  2957     /**
  2958      * Returns the string representation of the <code>int</code> argument.
  2959      * <p>
  2960      * The representation is exactly the one returned by the
  2961      * <code>Integer.toString</code> method of one argument.
  2962      *
  2963      * @param   i   an <code>int</code>.
  2964      * @return  a string representation of the <code>int</code> argument.
  2965      * @see     java.lang.Integer#toString(int, int)
  2966      */
  2967     public static String valueOf(int i) {
  2968         return Integer.toString(i);
  2969     }
  2970 
  2971     /**
  2972      * Returns the string representation of the <code>long</code> argument.
  2973      * <p>
  2974      * The representation is exactly the one returned by the
  2975      * <code>Long.toString</code> method of one argument.
  2976      *
  2977      * @param   l   a <code>long</code>.
  2978      * @return  a string representation of the <code>long</code> argument.
  2979      * @see     java.lang.Long#toString(long)
  2980      */
  2981     public static String valueOf(long l) {
  2982         return Long.toString(l);
  2983     }
  2984 
  2985     /**
  2986      * Returns the string representation of the <code>float</code> argument.
  2987      * <p>
  2988      * The representation is exactly the one returned by the
  2989      * <code>Float.toString</code> method of one argument.
  2990      *
  2991      * @param   f   a <code>float</code>.
  2992      * @return  a string representation of the <code>float</code> argument.
  2993      * @see     java.lang.Float#toString(float)
  2994      */
  2995     public static String valueOf(float f) {
  2996         return Float.toString(f);
  2997     }
  2998 
  2999     /**
  3000      * Returns the string representation of the <code>double</code> argument.
  3001      * <p>
  3002      * The representation is exactly the one returned by the
  3003      * <code>Double.toString</code> method of one argument.
  3004      *
  3005      * @param   d   a <code>double</code>.
  3006      * @return  a  string representation of the <code>double</code> argument.
  3007      * @see     java.lang.Double#toString(double)
  3008      */
  3009     public static String valueOf(double d) {
  3010         return Double.toString(d);
  3011     }
  3012 
  3013     /**
  3014      * Returns a canonical representation for the string object.
  3015      * <p>
  3016      * A pool of strings, initially empty, is maintained privately by the
  3017      * class <code>String</code>.
  3018      * <p>
  3019      * When the intern method is invoked, if the pool already contains a
  3020      * string equal to this <code>String</code> object as determined by
  3021      * the {@link #equals(Object)} method, then the string from the pool is
  3022      * returned. Otherwise, this <code>String</code> object is added to the
  3023      * pool and a reference to this <code>String</code> object is returned.
  3024      * <p>
  3025      * It follows that for any two strings <code>s</code> and <code>t</code>,
  3026      * <code>s.intern()&nbsp;==&nbsp;t.intern()</code> is <code>true</code>
  3027      * if and only if <code>s.equals(t)</code> is <code>true</code>.
  3028      * <p>
  3029      * All literal strings and string-valued constant expressions are
  3030      * interned. String literals are defined in section 3.10.5 of the
  3031      * <cite>The Java&trade; Language Specification</cite>.
  3032      *
  3033      * @return  a string that has the same contents as this string, but is
  3034      *          guaranteed to be from a pool of unique strings.
  3035      */
  3036     public native String intern();
  3037 }