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