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