2003-03-30 07:38:28 +02:00
|
|
|
/* String.java -- immutable character sequences; the object of string literals
|
Character.java (SIZE, [...]): New fields from Classpath.
* java/lang/Character.java (SIZE, MAX_CACHE, charCache,
MIN_SURROGATE, MAX_SURROGATE): New fields from Classpath.
(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE, MIN_LOW_SURROGATE,
MAX_LOW_SURROGATE): Javadoc fixes.
(valueOf, reverseBytes, isHighSurrogate, isLowSurrogate,
isSurrogatePair, toCodePoint, codePointAt, codePointBefore): New
methods from Classpath.
* java/lang/String.java (codePointAt, codePointBefore,
codePointCount, contains, replace): New methods from Classpath.
(contentEquals): Declare.
* java/lang/natString.cc (contentEquals): New method.
From-SVN: r109445
2006-01-07 01:46:28 +01:00
|
|
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
2003-03-30 07:38:28 +02:00
|
|
|
Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of GNU Classpath.
|
|
|
|
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
2005-06-30 05:22:09 +02:00
|
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301 USA.
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
Linking this library statically or dynamically with other modules is
|
|
|
|
making a combined work based on this library. Thus, the terms and
|
|
|
|
conditions of the GNU General Public License cover the whole
|
|
|
|
combination.
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent
|
|
|
|
modules, and to copy and distribute the resulting executable under
|
|
|
|
terms of your choice, provided that you also meet, for each linked
|
|
|
|
independent module, the terms and conditions of the license of that
|
|
|
|
module. An independent module is a module which is not derived from
|
|
|
|
or based on this library. If you modify this library, you may extend
|
|
|
|
this exception to your version of the library, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version. */
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
package java.lang;
|
2003-03-30 07:38:28 +02:00
|
|
|
|
2000-05-19 19:55:34 +02:00
|
|
|
import java.io.Serializable;
|
2004-07-17 16:04:45 +02:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2000-05-19 19:55:34 +02:00
|
|
|
import java.lang.Comparable;
|
2000-09-13 08:36:25 +02:00
|
|
|
import java.util.Comparator;
|
2000-11-18 03:29:13 +01:00
|
|
|
import java.util.Locale;
|
2003-03-30 08:43:45 +02:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.PatternSyntaxException;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
/**
|
2003-03-30 07:38:28 +02:00
|
|
|
* Strings represent an immutable set of characters. All String literals
|
|
|
|
* are instances of this class, and two string literals with the same contents
|
|
|
|
* refer to the same String object.
|
|
|
|
*
|
|
|
|
* <p>This class also includes a number of methods for manipulating the
|
|
|
|
* contents of strings (of course, creating a new object if there are any
|
|
|
|
* changes, as String is immutable). Case mapping relies on Unicode 3.0.0
|
|
|
|
* standards, where some character sequences have a different number of
|
|
|
|
* characters in the uppercase version than the lower case.
|
|
|
|
*
|
|
|
|
* <p>Strings are special, in that they are the only object with an overloaded
|
|
|
|
* operator. When you use '+' with at least one String argument, both
|
|
|
|
* arguments have String conversion performed on them, and another String (not
|
|
|
|
* guaranteed to be unique) results.
|
|
|
|
*
|
|
|
|
* <p>String is special-cased when doing data serialization - rather than
|
|
|
|
* listing the fields of this class, a String object is converted to a string
|
|
|
|
* literal in the object stream.
|
|
|
|
*
|
|
|
|
* @author Paul N. Fisher
|
2004-07-17 16:04:45 +02:00
|
|
|
* @author Eric Blake (ebb9@email.byu.edu)
|
|
|
|
* @author Per Bothner (bothner@cygnus.com)
|
2003-03-30 07:38:28 +02:00
|
|
|
* @since 1.0
|
|
|
|
* @status updated to 1.4
|
1999-04-07 16:42:40 +02:00
|
|
|
*/
|
2001-10-02 22:59:31 +02:00
|
|
|
public final class String implements Serializable, Comparable, CharSequence
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
// WARNING: String is a CORE class in the bootstrap cycle. See the comments
|
|
|
|
// in vm/reference/java/lang/Runtime for implications of this fact.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is probably not necessary because this class is special cased already
|
|
|
|
* but it will avoid showing up as a discrepancy when comparing SUIDs.
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = -6849794470754667710L;
|
|
|
|
|
2003-03-31 03:03:21 +02:00
|
|
|
/**
|
|
|
|
* This is the object that holds the characters that make up the
|
|
|
|
* String. It might be a char[], or it could be String. It could
|
|
|
|
* even be `this'. The actual characters can't be located using
|
|
|
|
* pure Java code.
|
|
|
|
* @see #boffset
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
private Object data;
|
2003-03-31 03:03:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a <emph>byte</emph> offset of the actual characters from
|
|
|
|
* the start of the character-holding object. Don't use this field
|
|
|
|
* in Java code.
|
|
|
|
*/
|
|
|
|
private int boffset;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the number of characters in value. Package visible for use
|
|
|
|
* by trusted code.
|
|
|
|
*/
|
2003-03-24 01:50:18 +01:00
|
|
|
int count;
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 08:43:45 +02:00
|
|
|
/**
|
|
|
|
* Caches the result of hashCode(). If this value is zero, the hashcode
|
|
|
|
* is considered uncached (even if 0 is the correct hash value).
|
|
|
|
*/
|
|
|
|
private int cachedHashCode;
|
|
|
|
|
2001-09-05 21:32:57 +02:00
|
|
|
/**
|
|
|
|
* An implementation for {@link CASE_INSENSITIVE_ORDER}.
|
2003-03-30 07:38:28 +02:00
|
|
|
* This must be {@link Serializable}. The class name is dictated by
|
|
|
|
* compatibility with Sun's JDK.
|
2001-09-05 21:32:57 +02:00
|
|
|
*/
|
|
|
|
private static final class CaseInsensitiveComparator
|
|
|
|
implements Comparator, Serializable
|
2000-11-18 03:29:13 +01:00
|
|
|
{
|
2001-09-05 21:32:57 +02:00
|
|
|
/**
|
2003-03-30 07:38:28 +02:00
|
|
|
* Compatible with JDK 1.2.
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 8575799808933029326L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default private constructor generates unnecessary overhead.
|
2001-09-05 21:32:57 +02:00
|
|
|
*/
|
|
|
|
CaseInsensitiveComparator() {}
|
|
|
|
|
|
|
|
/**
|
2003-03-30 07:38:28 +02:00
|
|
|
* Compares to Strings, using
|
2001-09-05 21:32:57 +02:00
|
|
|
* <code>String.compareToIgnoreCase(String)</code>.
|
2003-03-30 07:38:28 +02:00
|
|
|
*
|
2001-09-05 21:32:57 +02:00
|
|
|
* @param o1 the first string
|
|
|
|
* @param o2 the second string
|
|
|
|
* @return < 0, 0, or > 0 depending on the case-insensitive
|
|
|
|
* comparison of the two strings.
|
|
|
|
* @throws NullPointerException if either argument is null
|
|
|
|
* @throws ClassCastException if either argument is not a String
|
|
|
|
* @see #compareToIgnoreCase(String)
|
|
|
|
*/
|
|
|
|
public int compare(Object o1, Object o2)
|
2000-09-13 08:36:25 +02:00
|
|
|
{
|
2001-09-05 21:32:57 +02:00
|
|
|
return ((String) o1).compareToIgnoreCase((String) o2);
|
2000-11-18 03:29:13 +01:00
|
|
|
}
|
2003-03-30 07:38:28 +02:00
|
|
|
} // class CaseInsensitiveComparator
|
2001-09-05 21:32:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A Comparator that uses <code>String.compareToIgnoreCase(String)</code>.
|
2003-03-30 07:38:28 +02:00
|
|
|
* This comparator is {@link Serializable}. Note that it ignores Locale,
|
|
|
|
* for that, you want a Collator.
|
2001-09-05 21:32:57 +02:00
|
|
|
*
|
2003-03-30 07:38:28 +02:00
|
|
|
* @see Collator#compare(String, String)
|
2001-09-05 21:32:57 +02:00
|
|
|
* @since 1.2
|
|
|
|
*/
|
|
|
|
public static final Comparator CASE_INSENSITIVE_ORDER
|
|
|
|
= new CaseInsensitiveComparator();
|
2000-09-13 08:36:25 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates an empty String (length 0). Unless you really need a new object,
|
|
|
|
* consider using <code>""</code> instead.
|
|
|
|
*/
|
2003-03-30 08:43:45 +02:00
|
|
|
public String()
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 08:43:45 +02:00
|
|
|
data = "".data;
|
|
|
|
boffset = 0;
|
|
|
|
count = 0;
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Copies the contents of a String to a new String. Since Strings are
|
|
|
|
* immutable, only a shallow copy is performed.
|
|
|
|
*
|
|
|
|
* @param str String to copy
|
|
|
|
* @throws NullPointerException if value is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(String str)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
data = str.data;
|
|
|
|
boffset = str.boffset;
|
|
|
|
count = str.count;
|
2003-03-30 08:43:45 +02:00
|
|
|
cachedHashCode = str.cachedHashCode;
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the character sequence of the char array.
|
|
|
|
* Subsequent changes to data do not affect the String.
|
|
|
|
*
|
|
|
|
* @param data char array to copy
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(char[] data)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
init(data, 0, data.length, false);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the character sequence of a subarray of
|
|
|
|
* characters. The string starts at offset, and copies count chars.
|
|
|
|
* Subsequent changes to data do not affect the String.
|
|
|
|
*
|
|
|
|
* @param data char array to copy
|
|
|
|
* @param offset position (base 0) to start copying out of data
|
|
|
|
* @param count the number of characters from data to copy
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
2004-07-17 16:04:45 +02:00
|
|
|
* || offset + count > data.length)
|
2003-03-30 07:38:28 +02:00
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(char[] data, int offset, int count)
|
2001-12-11 19:01:40 +01:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
init(data, offset, count, false);
|
2001-12-11 19:01:40 +01:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using an 8-bit array of integer values, starting at
|
|
|
|
* an offset, and copying up to the count. Each character c, using
|
|
|
|
* corresponding byte b, is created in the new String as if by performing:
|
|
|
|
*
|
|
|
|
* <pre>
|
2004-07-17 16:04:45 +02:00
|
|
|
* c = (char) (((hibyte & 0xff) << 8) | (b & 0xff))
|
2003-03-30 07:38:28 +02:00
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* @param ascii array of integer values
|
|
|
|
* @param hibyte top byte of each Unicode character
|
|
|
|
* @param offset position (base 0) to start copying out of ascii
|
|
|
|
* @param count the number of characters from ascii to copy
|
|
|
|
* @throws NullPointerException if ascii is null
|
|
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
2004-07-17 16:04:45 +02:00
|
|
|
* || offset + count > ascii.length)
|
2003-03-30 07:38:28 +02:00
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
* @see #String(byte[])
|
|
|
|
* @see #String(byte[], String)
|
|
|
|
* @see #String(byte[], int, int)
|
|
|
|
* @see #String(byte[], int, int, String)
|
|
|
|
* @deprecated use {@link #String(byte[], int, int, String)} to perform
|
|
|
|
* correct encoding
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(byte[] ascii, int hibyte, int offset, int count)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
init(ascii, hibyte, offset, count);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using an 8-bit array of integer values. Each
|
|
|
|
* character c, using corresponding byte b, is created in the new String
|
|
|
|
* as if by performing:
|
|
|
|
*
|
|
|
|
* <pre>
|
2004-07-17 16:04:45 +02:00
|
|
|
* c = (char) (((hibyte & 0xff) << 8) | (b & 0xff))
|
2003-03-30 07:38:28 +02:00
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* @param ascii array of integer values
|
|
|
|
* @param hibyte top byte of each Unicode character
|
|
|
|
* @throws NullPointerException if ascii is null
|
|
|
|
* @see #String(byte[])
|
|
|
|
* @see #String(byte[], String)
|
|
|
|
* @see #String(byte[], int, int)
|
|
|
|
* @see #String(byte[], int, int, String)
|
|
|
|
* @see #String(byte[], int, int, int)
|
|
|
|
* @deprecated use {@link #String(byte[], String)} to perform
|
|
|
|
* correct encoding
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(byte[] ascii, int hibyte)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
init(ascii, hibyte, 0, ascii.length);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the portion of the byte array starting at the
|
|
|
|
* offset and ending at offset + count. Uses the specified encoding type
|
|
|
|
* to decode the byte array, so the resulting string may be longer or
|
|
|
|
* shorter than the byte array. For more decoding control, use
|
|
|
|
* {@link java.nio.charset.CharsetDecoder}, and for valid character sets,
|
|
|
|
* see {@link java.nio.charset.Charset}. The behavior is not specified if
|
|
|
|
* the decoder encounters invalid characters; this implementation throws
|
|
|
|
* an Error.
|
|
|
|
*
|
|
|
|
* @param data byte array to copy
|
|
|
|
* @param offset the offset to start at
|
|
|
|
* @param count the number of characters in the array to use
|
|
|
|
* @param encoding the name of the encoding to use
|
|
|
|
* @throws NullPointerException if data or encoding is null
|
|
|
|
* @throws IndexOutOfBoundsException if offset or count is incorrect
|
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
* @throws UnsupportedEncodingException if encoding is not found
|
|
|
|
* @throws Error if the decoding fails
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(byte[] data, int offset, int count, String encoding)
|
2003-03-30 07:38:28 +02:00
|
|
|
throws UnsupportedEncodingException
|
2002-06-13 20:16:26 +02:00
|
|
|
{
|
2003-03-30 23:14:32 +02:00
|
|
|
init (data, offset, count, encoding);
|
2002-06-13 20:16:26 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the byte array. Uses the specified encoding
|
|
|
|
* type to decode the byte array, so the resulting string may be longer or
|
|
|
|
* shorter than the byte array. For more decoding control, use
|
|
|
|
* {@link java.nio.charset.CharsetDecoder}, and for valid character sets,
|
|
|
|
* see {@link java.nio.charset.Charset}. The behavior is not specified if
|
|
|
|
* the decoder encounters invalid characters; this implementation throws
|
|
|
|
* an Error.
|
|
|
|
*
|
|
|
|
* @param data byte array to copy
|
|
|
|
* @param encoding the name of the encoding to use
|
|
|
|
* @throws NullPointerException if data or encoding is null
|
|
|
|
* @throws UnsupportedEncodingException if encoding is not found
|
|
|
|
* @throws Error if the decoding fails
|
|
|
|
* @see #String(byte[], int, int, String)
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(byte[] data, String encoding)
|
2003-03-30 07:38:28 +02:00
|
|
|
throws UnsupportedEncodingException
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-31 03:03:21 +02:00
|
|
|
this(data, 0, data.length, encoding);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the portion of the byte array starting at the
|
|
|
|
* offset and ending at offset + count. Uses the encoding of the platform's
|
|
|
|
* default charset, so the resulting string may be longer or shorter than
|
|
|
|
* the byte array. For more decoding control, use
|
|
|
|
* {@link java.nio.charset.CharsetDecoder}. The behavior is not specified
|
|
|
|
* if the decoder encounters invalid characters; this implementation throws
|
|
|
|
* an Error.
|
|
|
|
*
|
|
|
|
* @param data byte array to copy
|
|
|
|
* @param offset the offset to start at
|
|
|
|
* @param count the number of characters in the array to use
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @throws IndexOutOfBoundsException if offset or count is incorrect
|
|
|
|
* @throws Error if the decoding fails
|
|
|
|
* @see #String(byte[], int, int, String)
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(byte[] data, int offset, int count)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2003-03-30 23:14:32 +02:00
|
|
|
init (data, offset, count,
|
1999-04-07 16:42:40 +02:00
|
|
|
System.getProperty("file.encoding", "8859_1"));
|
|
|
|
}
|
|
|
|
catch (UnsupportedEncodingException x1)
|
|
|
|
{
|
|
|
|
// Maybe the default encoding is bad.
|
|
|
|
try
|
|
|
|
{
|
2003-03-30 23:14:32 +02:00
|
|
|
init (data, offset, count, "8859_1");
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
catch (UnsupportedEncodingException x2)
|
|
|
|
{
|
|
|
|
// We know this can't happen.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the byte array. Uses the encoding of the
|
|
|
|
* platform's default charset, so the resulting string may be longer or
|
|
|
|
* shorter than the byte array. For more decoding control, use
|
|
|
|
* {@link java.nio.charset.CharsetDecoder}. The behavior is not specified
|
|
|
|
* if the decoder encounters invalid characters; this implementation throws
|
|
|
|
* an Error.
|
|
|
|
*
|
|
|
|
* @param data byte array to copy
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @throws Error if the decoding fails
|
|
|
|
* @see #String(byte[], int, int)
|
|
|
|
* @see #String(byte[], int, int, String)
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(byte[] data)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-31 03:03:21 +02:00
|
|
|
this(data, 0, data.length);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the character sequence represented by
|
|
|
|
* the StringBuffer. Subsequent changes to buf do not affect the String.
|
|
|
|
*
|
|
|
|
* @param buffer StringBuffer to copy
|
|
|
|
* @throws NullPointerException if buffer is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String(StringBuffer buffer)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
synchronized (buffer)
|
|
|
|
{
|
2003-03-31 03:03:21 +02:00
|
|
|
// Share unless buffer is 3/4 empty.
|
|
|
|
boolean should_copy = ((buffer.count << 2) < buffer.value.length);
|
|
|
|
if (! should_copy)
|
|
|
|
buffer.shared = true;
|
|
|
|
init (buffer.value, 0, buffer.count, ! should_copy);
|
2003-03-30 07:38:28 +02:00
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2005-05-10 20:28:31 +02:00
|
|
|
/**
|
|
|
|
* Creates a new String using the character sequence represented by
|
|
|
|
* the StringBuilder. Subsequent changes to buf do not affect the String.
|
|
|
|
*
|
|
|
|
* @param buffer StringBuilder to copy
|
|
|
|
* @throws NullPointerException if buffer is null
|
|
|
|
*/
|
|
|
|
public String(StringBuilder buffer)
|
|
|
|
{
|
|
|
|
this(buffer.value, 0, buffer.count);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Special constructor which can share an array when safe to do so.
|
|
|
|
*
|
|
|
|
* @param data the characters to copy
|
|
|
|
* @param offset the location to start from
|
|
|
|
* @param count the number of characters to use
|
|
|
|
* @param dont_copy true if the array is trusted, and need not be copied
|
|
|
|
* @throws NullPointerException if chars is null
|
|
|
|
* @throws StringIndexOutOfBoundsException if bounds check fails
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
String(char[] data, int offset, int count, boolean dont_copy)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
init(data, offset, count, dont_copy);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
// This is used by gnu.gcj.runtime.StringBuffer, so it must have
|
|
|
|
// package-private protection. It is accessed via CNI and so avoids
|
|
|
|
// ordinary protection mechanisms.
|
2003-03-30 23:14:32 +02:00
|
|
|
String(gnu.gcj.runtime.StringBuffer buffer)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
// No need to synchronize or mark the buffer, since we know it is
|
|
|
|
// only used once.
|
2003-07-28 18:12:00 +02:00
|
|
|
init (buffer);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the number of characters contained in this String.
|
|
|
|
*
|
|
|
|
* @return the length of this String
|
|
|
|
*/
|
|
|
|
public int length()
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the character located at the specified index within this String.
|
|
|
|
*
|
|
|
|
* @param index position of character to return (base 0)
|
|
|
|
* @return character located at position index
|
|
|
|
* @throws IndexOutOfBoundsException if index < 0 || index >= length()
|
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native char charAt(int index);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
Character.java (SIZE, [...]): New fields from Classpath.
* java/lang/Character.java (SIZE, MAX_CACHE, charCache,
MIN_SURROGATE, MAX_SURROGATE): New fields from Classpath.
(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE, MIN_LOW_SURROGATE,
MAX_LOW_SURROGATE): Javadoc fixes.
(valueOf, reverseBytes, isHighSurrogate, isLowSurrogate,
isSurrogatePair, toCodePoint, codePointAt, codePointBefore): New
methods from Classpath.
* java/lang/String.java (codePointAt, codePointBefore,
codePointCount, contains, replace): New methods from Classpath.
(contentEquals): Declare.
* java/lang/natString.cc (contentEquals): New method.
From-SVN: r109445
2006-01-07 01:46:28 +01:00
|
|
|
/**
|
|
|
|
* Get the code point at the specified index. This is like #charAt(int),
|
|
|
|
* but if the character is the start of a surrogate pair, and the
|
|
|
|
* following character completes the pair, then the corresponding
|
|
|
|
* supplementary code point is returned.
|
|
|
|
* @param index the index of the codepoint to get, starting at 0
|
|
|
|
* @return the codepoint at the specified index
|
|
|
|
* @throws IndexOutOfBoundsException if index is negative or >= length()
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public synchronized int codePointAt(int index)
|
|
|
|
{
|
|
|
|
// Use the CharSequence overload as we get better range checking
|
|
|
|
// this way.
|
|
|
|
return Character.codePointAt(this, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the code point before the specified index. This is like
|
|
|
|
* #codePointAt(int), but checks the characters at <code>index-1</code> and
|
|
|
|
* <code>index-2</code> to see if they form a supplementary code point.
|
|
|
|
* @param index the index just past the codepoint to get, starting at 0
|
|
|
|
* @return the codepoint at the specified index
|
|
|
|
* @throws IndexOutOfBoundsException if index is negative or >= length()
|
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public synchronized int codePointBefore(int index)
|
|
|
|
{
|
|
|
|
// Use the CharSequence overload as we get better range checking
|
|
|
|
// this way.
|
|
|
|
return Character.codePointBefore(this, index);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Copies characters from this String starting at a specified start index,
|
|
|
|
* ending at a specified stop index, to a character array starting at
|
|
|
|
* a specified destination begin index.
|
|
|
|
*
|
|
|
|
* @param srcBegin index to begin copying characters from this String
|
|
|
|
* @param srcEnd index after the last character to be copied from this String
|
|
|
|
* @param dst character array which this String is copied into
|
|
|
|
* @param dstBegin index to start writing characters into dst
|
|
|
|
* @throws NullPointerException if dst is null
|
|
|
|
* @throws IndexOutOfBoundsException if any indices are out of bounds
|
|
|
|
* (while unspecified, source problems cause a
|
|
|
|
* StringIndexOutOfBoundsException, and dst problems cause an
|
|
|
|
* ArrayIndexOutOfBoundsException)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native void getChars(int srcBegin, int srcEnd,
|
|
|
|
char[] dst, int dstBegin);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Copies the low byte of each character from this String starting at a
|
|
|
|
* specified start index, ending at a specified stop index, to a byte array
|
|
|
|
* starting at a specified destination begin index.
|
|
|
|
*
|
|
|
|
* @param srcBegin index to being copying characters from this String
|
|
|
|
* @param srcEnd index after the last character to be copied from this String
|
|
|
|
* @param dst byte array which each low byte of this String is copied into
|
|
|
|
* @param dstBegin index to start writing characters into dst
|
|
|
|
* @throws NullPointerException if dst is null and copy length is non-zero
|
|
|
|
* @throws IndexOutOfBoundsException if any indices are out of bounds
|
|
|
|
* (while unspecified, source problems cause a
|
|
|
|
* StringIndexOutOfBoundsException, and dst problems cause an
|
|
|
|
* ArrayIndexOutOfBoundsException)
|
|
|
|
* @see #getBytes()
|
|
|
|
* @see #getBytes(String)
|
|
|
|
* @deprecated use {@link #getBytes()}, which uses a char to byte encoder
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native void getBytes(int srcBegin, int srcEnd,
|
|
|
|
byte[] dst, int dstBegin);
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the Unicode characters in this String to a byte array. Uses the
|
|
|
|
* specified encoding method, so the result may be longer or shorter than
|
|
|
|
* the String. For more encoding control, use
|
|
|
|
* {@link java.nio.charset.CharsetEncoder}, and for valid character sets,
|
|
|
|
* see {@link java.nio.charset.Charset}. The behavior is not specified if
|
|
|
|
* the encoder encounters a problem; this implementation returns null.
|
|
|
|
*
|
|
|
|
* @param enc encoding name
|
|
|
|
* @return the resulting byte array, or null on a problem
|
|
|
|
* @throws NullPointerException if enc is null
|
|
|
|
* @throws UnsupportedEncodingException if encoding is not supported
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native byte[] getBytes(String enc)
|
2003-03-30 07:38:28 +02:00
|
|
|
throws UnsupportedEncodingException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the Unicode characters in this String to a byte array. Uses the
|
|
|
|
* encoding of the platform's default charset, so the result may be longer
|
|
|
|
* or shorter than the String. For more encoding control, use
|
|
|
|
* {@link java.nio.charset.CharsetEncoder}. The behavior is not specified if
|
|
|
|
* the encoder encounters a problem; this implementation returns null.
|
|
|
|
*
|
|
|
|
* @return the resulting byte array, or null on a problem
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public byte[] getBytes()
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
1999-04-21 14:12:39 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return getBytes (System.getProperty("file.encoding", "8859_1"));
|
|
|
|
}
|
|
|
|
catch (UnsupportedEncodingException x)
|
|
|
|
{
|
|
|
|
// This probably shouldn't happen, but could if file.encoding
|
|
|
|
// is somehow changed to a value we don't understand.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return getBytes ("8859_1");
|
|
|
|
}
|
|
|
|
catch (UnsupportedEncodingException x2)
|
|
|
|
{
|
|
|
|
// This really shouldn't happen, because the 8859_1
|
|
|
|
// encoding should always be available.
|
|
|
|
throw new InternalError ("couldn't find 8859_1 encoder");
|
|
|
|
}
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Predicate which compares anObject to this. This is true only for Strings
|
|
|
|
* with the same character sequence.
|
|
|
|
*
|
|
|
|
* @param anObject the object to compare
|
|
|
|
* @return true if anObject is semantically equal to this
|
|
|
|
* @see #compareTo(String)
|
|
|
|
* @see #equalsIgnoreCase(String)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native boolean equals(Object anObject);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 08:43:45 +02:00
|
|
|
/**
|
|
|
|
* Compares the given StringBuffer to this String. This is true if the
|
|
|
|
* StringBuffer has the same content as this String at this moment.
|
|
|
|
*
|
|
|
|
* @param buffer the StringBuffer to compare to
|
|
|
|
* @return true if StringBuffer has the same character sequence
|
|
|
|
* @throws NullPointerException if the given StringBuffer is null
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public native boolean contentEquals(StringBuffer buffer);
|
|
|
|
|
Character.java (SIZE, [...]): New fields from Classpath.
* java/lang/Character.java (SIZE, MAX_CACHE, charCache,
MIN_SURROGATE, MAX_SURROGATE): New fields from Classpath.
(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE, MIN_LOW_SURROGATE,
MAX_LOW_SURROGATE): Javadoc fixes.
(valueOf, reverseBytes, isHighSurrogate, isLowSurrogate,
isSurrogatePair, toCodePoint, codePointAt, codePointBefore): New
methods from Classpath.
* java/lang/String.java (codePointAt, codePointBefore,
codePointCount, contains, replace): New methods from Classpath.
(contentEquals): Declare.
* java/lang/natString.cc (contentEquals): New method.
From-SVN: r109445
2006-01-07 01:46:28 +01:00
|
|
|
/**
|
|
|
|
* Compares the given CharSequence to this String. This is true if
|
|
|
|
* the CharSequence has the same content as this String at this
|
|
|
|
* moment.
|
|
|
|
*
|
|
|
|
* @param seq the CharSequence to compare to
|
|
|
|
* @return true if CharSequence has the same character sequence
|
|
|
|
* @throws NullPointerException if the given CharSequence is null
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public native boolean contentEquals(CharSequence seq);
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Compares a String to this String, ignoring case. This does not handle
|
|
|
|
* multi-character capitalization exceptions; instead the comparison is
|
|
|
|
* made on a character-by-character basis, and is true if:<br><ul>
|
|
|
|
* <li><code>c1 == c2</code></li>
|
|
|
|
* <li><code>Character.toUpperCase(c1)
|
|
|
|
* == Character.toUpperCase(c2)</code></li>
|
|
|
|
* <li><code>Character.toLowerCase(c1)
|
|
|
|
* == Character.toLowerCase(c2)</code></li>
|
|
|
|
* </ul>
|
|
|
|
*
|
|
|
|
* @param anotherString String to compare to this String
|
|
|
|
* @return true if anotherString is equal, ignoring case
|
|
|
|
* @see #equals(Object)
|
|
|
|
* @see Character#toUpperCase(char)
|
|
|
|
* @see Character#toLowerCase(char)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native boolean equalsIgnoreCase(String anotherString);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Compares this String and another String (case sensitive,
|
|
|
|
* lexicographically). The result is less than 0 if this string sorts
|
|
|
|
* before the other, 0 if they are equal, and greater than 0 otherwise.
|
|
|
|
* After any common starting sequence is skipped, the result is
|
|
|
|
* <code>this.charAt(k) - anotherString.charAt(k)</code> if both strings
|
|
|
|
* have characters remaining, or
|
|
|
|
* <code>this.length() - anotherString.length()</code> if one string is
|
|
|
|
* a subsequence of the other.
|
|
|
|
*
|
|
|
|
* @param anotherString the String to compare against
|
|
|
|
* @return the comparison
|
|
|
|
* @throws NullPointerException if anotherString is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native int compareTo(String anotherString);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Behaves like <code>compareTo(java.lang.String)</code> unless the Object
|
|
|
|
* is not a <code>String</code>. Then it throws a
|
|
|
|
* <code>ClassCastException</code>.
|
|
|
|
*
|
|
|
|
* @param o the object to compare against
|
|
|
|
* @return the comparison
|
|
|
|
* @throws NullPointerException if o is null
|
|
|
|
* @throws ClassCastException if o is not a <code>String</code>
|
|
|
|
* @since 1.2
|
|
|
|
*/
|
|
|
|
public int compareTo(Object o)
|
2000-05-19 19:55:34 +02:00
|
|
|
{
|
2003-03-30 07:38:28 +02:00
|
|
|
return compareTo((String) o);
|
2000-05-19 19:55:34 +02:00
|
|
|
}
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares this String and another String (case insensitive). This
|
|
|
|
* comparison is <em>similar</em> to equalsIgnoreCase, in that it ignores
|
|
|
|
* locale and multi-characater capitalization, and compares characters
|
|
|
|
* after performing
|
|
|
|
* <code>Character.toLowerCase(Character.toUpperCase(c))</code> on each
|
|
|
|
* character of the string. This is unsatisfactory for locale-based
|
|
|
|
* comparison, in which case you should use {@link java.text.Collator}.
|
|
|
|
*
|
2004-07-17 16:04:45 +02:00
|
|
|
* @param str the string to compare against
|
2003-03-30 07:38:28 +02:00
|
|
|
* @return the comparison
|
|
|
|
* @see Collator#compare(String, String)
|
|
|
|
* @since 1.2
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public int compareToIgnoreCase(String str)
|
2000-09-13 08:36:25 +02:00
|
|
|
{
|
|
|
|
return this.toUpperCase().toLowerCase().compareTo(
|
|
|
|
str.toUpperCase().toLowerCase());
|
|
|
|
}
|
2000-05-19 19:55:34 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Predicate which determines if this String matches another String
|
|
|
|
* starting at a specified offset for each String and continuing
|
|
|
|
* for a specified length. Indices out of bounds are harmless, and give
|
|
|
|
* a false result.
|
|
|
|
*
|
|
|
|
* @param toffset index to start comparison at for this String
|
|
|
|
* @param other String to compare region to this String
|
2004-07-17 16:04:45 +02:00
|
|
|
* @param ooffset index to start comparison at for other
|
2003-03-30 07:38:28 +02:00
|
|
|
* @param len number of characters to compare
|
|
|
|
* @return true if regions match (case sensitive)
|
|
|
|
* @throws NullPointerException if other is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native boolean regionMatches(int toffset,
|
|
|
|
String other, int ooffset, int len);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Predicate which determines if this String matches another String
|
|
|
|
* starting at a specified offset for each String and continuing
|
|
|
|
* for a specified length, optionally ignoring case. Indices out of bounds
|
|
|
|
* are harmless, and give a false result. Case comparisons are based on
|
|
|
|
* <code>Character.toLowerCase()</code> and
|
|
|
|
* <code>Character.toUpperCase()</code>, not on multi-character
|
|
|
|
* capitalization expansions.
|
|
|
|
*
|
|
|
|
* @param ignoreCase true if case should be ignored in comparision
|
|
|
|
* @param toffset index to start comparison at for this String
|
|
|
|
* @param other String to compare region to this String
|
|
|
|
* @param oofset index to start comparison at for other
|
|
|
|
* @param len number of characters to compare
|
|
|
|
* @return true if regions match, false otherwise
|
|
|
|
* @throws NullPointerException if other is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native boolean regionMatches(boolean ignoreCase, int toffset,
|
|
|
|
String other, int ooffset, int len);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Predicate which determines if this String contains the given prefix,
|
|
|
|
* beginning comparison at toffset. The result is false if toffset is
|
|
|
|
* negative or greater than this.length(), otherwise it is the same as
|
2005-05-15 23:09:45 +02:00
|
|
|
* <code>this.substring(toffset).startsWith(prefix)</code>.
|
2003-03-30 07:38:28 +02:00
|
|
|
*
|
|
|
|
* @param prefix String to compare
|
|
|
|
* @param toffset offset for this String where comparison starts
|
|
|
|
* @return true if this String starts with prefix
|
|
|
|
* @throws NullPointerException if prefix is null
|
|
|
|
* @see #regionMatches(boolean, int, String, int, int)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native boolean startsWith(String prefix, int toffset);
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Predicate which determines if this String starts with a given prefix.
|
|
|
|
* If the prefix is an empty String, true is returned.
|
|
|
|
*
|
2004-07-17 16:04:45 +02:00
|
|
|
* @param prefix String to compare
|
2003-03-30 07:38:28 +02:00
|
|
|
* @return true if this String starts with the prefix
|
|
|
|
* @throws NullPointerException if prefix is null
|
|
|
|
* @see #startsWith(String, int)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public boolean startsWith(String prefix)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return startsWith (prefix, 0);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Predicate which determines if this String ends with a given suffix.
|
|
|
|
* If the suffix is an empty String, true is returned.
|
|
|
|
*
|
|
|
|
* @param suffix String to compare
|
|
|
|
* @return true if this String ends with the suffix
|
|
|
|
* @throws NullPointerException if suffix is null
|
|
|
|
* @see #regionMatches(boolean, int, String, int, int)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public boolean endsWith(String suffix)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return regionMatches (this.count - suffix.count, suffix, 0, suffix.count);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Computes the hashcode for this String. This is done with int arithmetic,
|
|
|
|
* where ** represents exponentiation, by this formula:<br>
|
|
|
|
* <code>s[0]*31**(n-1) + s[1]*31**(n-2) + ... + s[n-1]</code>.
|
|
|
|
*
|
|
|
|
* @return hashcode value of this String
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native int hashCode();
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the first instance of a character in this String.
|
|
|
|
*
|
|
|
|
* @param ch character to find
|
|
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public int indexOf(int ch)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 23:14:32 +02:00
|
|
|
return indexOf(ch, 0);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the first instance of a character in this String, starting at
|
|
|
|
* a given index. If starting index is less than 0, the search
|
|
|
|
* starts at the beginning of this String. If the starting index
|
|
|
|
* is greater than the length of this String, -1 is returned.
|
|
|
|
*
|
|
|
|
* @param ch character to find
|
|
|
|
* @param fromIndex index to start the search
|
|
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native int indexOf(int ch, int fromIndex);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the last instance of a character in this String.
|
|
|
|
*
|
|
|
|
* @param ch character to find
|
|
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public int lastIndexOf(int ch)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-31 03:03:21 +02:00
|
|
|
return lastIndexOf(ch, count - 1);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the last instance of a character in this String, starting at
|
|
|
|
* a given index. If starting index is greater than the maximum valid
|
|
|
|
* index, then the search begins at the end of this String. If the
|
|
|
|
* starting index is less than zero, -1 is returned.
|
|
|
|
*
|
|
|
|
* @param ch character to find
|
|
|
|
* @param fromIndex index to start the search
|
|
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native int lastIndexOf(int ch, int fromIndex);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the first instance of a String in this String.
|
|
|
|
*
|
|
|
|
* @param str String to find
|
|
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
|
|
* @throws NullPointerException if str is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public int indexOf(String str)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-30 23:14:32 +02:00
|
|
|
return indexOf(str, 0);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the first instance of a String in this String, starting at
|
|
|
|
* a given index. If starting index is less than 0, the search
|
|
|
|
* starts at the beginning of this String. If the starting index
|
|
|
|
* is greater than the length of this String, -1 is returned.
|
|
|
|
*
|
|
|
|
* @param str String to find
|
|
|
|
* @param fromIndex index to start the search
|
|
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
|
|
* @throws NullPointerException if str is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native int indexOf(String str, int fromIndex);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the last instance of a String in this String.
|
|
|
|
*
|
|
|
|
* @param str String to find
|
|
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
|
|
* @throws NullPointerException if str is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public int lastIndexOf(String str)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
2003-03-31 03:03:21 +02:00
|
|
|
return lastIndexOf(str, count - str.count);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Finds the last instance of a String in this String, starting at
|
|
|
|
* a given index. If starting index is greater than the maximum valid
|
|
|
|
* index, then the search begins at the end of this String. If the
|
|
|
|
* starting index is less than zero, -1 is returned.
|
|
|
|
*
|
|
|
|
* @param str String to find
|
|
|
|
* @param fromIndex index to start the search
|
|
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
|
|
* @throws NullPointerException if str is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public int lastIndexOf(String str, int fromIndex)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
if (fromIndex >= count)
|
|
|
|
fromIndex = count - str.count;
|
|
|
|
for (;; --fromIndex)
|
|
|
|
{
|
|
|
|
if (fromIndex < 0)
|
|
|
|
return -1;
|
|
|
|
if (startsWith(str, fromIndex))
|
|
|
|
return fromIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Creates a substring of this String, starting at a specified index
|
|
|
|
* and ending at the end of this String.
|
|
|
|
*
|
|
|
|
* @param begin index to start substring (base 0)
|
|
|
|
* @return new String which is a substring of this String
|
|
|
|
* @throws IndexOutOfBoundsException if begin < 0 || begin > length()
|
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
*/
|
2003-03-31 03:03:21 +02:00
|
|
|
public String substring(int begin)
|
2003-03-30 07:38:28 +02:00
|
|
|
{
|
2003-03-31 03:03:21 +02:00
|
|
|
return substring(begin, count);
|
2003-03-30 07:38:28 +02:00
|
|
|
}
|
|
|
|
|
2001-10-02 22:59:31 +02:00
|
|
|
/**
|
|
|
|
* Creates a substring of this String, starting at a specified index
|
|
|
|
* and ending at one character before a specified index.
|
2003-03-30 07:38:28 +02:00
|
|
|
*
|
|
|
|
* @param begin index to start substring (inclusive, base 0)
|
|
|
|
* @param end index to end at (exclusive)
|
2001-10-02 22:59:31 +02:00
|
|
|
* @return new String which is a substring of this String
|
2003-03-30 07:38:28 +02:00
|
|
|
* @throws IndexOutOfBoundsException if begin < 0 || end > length()
|
2004-07-17 16:04:45 +02:00
|
|
|
* || begin > end (while unspecified, this is a
|
2003-03-30 07:38:28 +02:00
|
|
|
* StringIndexOutOfBoundsException)
|
|
|
|
*/
|
2004-07-17 16:04:45 +02:00
|
|
|
public native String substring(int begin, int end);
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a substring of this String, starting at a specified index
|
|
|
|
* and ending at one character before a specified index. This behaves like
|
2004-07-17 16:04:45 +02:00
|
|
|
* <code>substring(begin, end)</code>.
|
2001-10-02 22:59:31 +02:00
|
|
|
*
|
2004-07-17 16:04:45 +02:00
|
|
|
* @param begin index to start substring (inclusive, base 0)
|
|
|
|
* @param end index to end at (exclusive)
|
2003-03-30 07:38:28 +02:00
|
|
|
* @return new String which is a substring of this String
|
|
|
|
* @throws IndexOutOfBoundsException if begin < 0 || end > length()
|
2004-07-17 16:04:45 +02:00
|
|
|
* || begin > end
|
2003-03-30 07:38:28 +02:00
|
|
|
* @since 1.4
|
2001-10-02 22:59:31 +02:00
|
|
|
*/
|
2004-07-17 16:04:45 +02:00
|
|
|
public CharSequence subSequence(int begin, int end)
|
2001-10-02 22:59:31 +02:00
|
|
|
{
|
2004-07-17 16:04:45 +02:00
|
|
|
return substring(begin, end);
|
2001-10-02 22:59:31 +02:00
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Concatenates a String to this String. This results in a new string unless
|
|
|
|
* one of the two originals is "".
|
|
|
|
*
|
|
|
|
* @param str String to append to this String
|
|
|
|
* @return newly concatenated String
|
|
|
|
* @throws NullPointerException if str is null
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native String concat(String str);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Replaces every instance of a character in this String with a new
|
|
|
|
* character. If no replacements occur, this is returned.
|
|
|
|
*
|
|
|
|
* @param oldChar the old character to replace
|
|
|
|
* @param newChar the new character
|
|
|
|
* @return new String with all instances of oldChar replaced with newChar
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native String replace(char oldChar, char newChar);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 08:43:45 +02:00
|
|
|
/**
|
|
|
|
* Test if this String matches a regular expression. This is shorthand for
|
|
|
|
* <code>{@link Pattern}.matches(regex, this)</code>.
|
|
|
|
*
|
|
|
|
* @param regex the pattern to match
|
|
|
|
* @return true if the pattern matches
|
|
|
|
* @throws NullPointerException if regex is null
|
|
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
|
|
* @see Pattern#matches(String, CharSequence)
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public boolean matches(String regex)
|
|
|
|
{
|
|
|
|
return Pattern.matches(regex, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces the first substring match of the regular expression with a
|
|
|
|
* given replacement. This is shorthand for <code>{@link Pattern}
|
|
|
|
* .compile(regex).matcher(this).replaceFirst(replacement)</code>.
|
|
|
|
*
|
|
|
|
* @param regex the pattern to match
|
|
|
|
* @param replacement the replacement string
|
|
|
|
* @return the modified string
|
|
|
|
* @throws NullPointerException if regex or replacement is null
|
|
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
|
|
* @see #replaceAll(String, String)
|
|
|
|
* @see Pattern#compile(String)
|
|
|
|
* @see Pattern#matcher(CharSequence)
|
|
|
|
* @see Matcher#replaceFirst(String)
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public String replaceFirst(String regex, String replacement)
|
|
|
|
{
|
|
|
|
return Pattern.compile(regex).matcher(this).replaceFirst(replacement);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces all matching substrings of the regular expression with a
|
|
|
|
* given replacement. This is shorthand for <code>{@link Pattern}
|
|
|
|
* .compile(regex).matcher(this).replaceAll(replacement)</code>.
|
|
|
|
*
|
|
|
|
* @param regex the pattern to match
|
|
|
|
* @param replacement the replacement string
|
|
|
|
* @return the modified string
|
|
|
|
* @throws NullPointerException if regex or replacement is null
|
|
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
|
|
* @see #replaceFirst(String, String)
|
|
|
|
* @see Pattern#compile(String)
|
|
|
|
* @see Pattern#matcher(CharSequence)
|
|
|
|
* @see Matcher#replaceAll(String)
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public String replaceAll(String regex, String replacement)
|
|
|
|
{
|
|
|
|
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Split this string around the matches of a regular expression. Each
|
|
|
|
* element of the returned array is the largest block of characters not
|
|
|
|
* terminated by the regular expression, in the order the matches are found.
|
|
|
|
*
|
|
|
|
* <p>The limit affects the length of the array. If it is positive, the
|
|
|
|
* array will contain at most n elements (n - 1 pattern matches). If
|
|
|
|
* negative, the array length is unlimited, but there can be trailing empty
|
|
|
|
* entries. if 0, the array length is unlimited, and trailing empty entries
|
|
|
|
* are discarded.
|
|
|
|
*
|
|
|
|
* <p>For example, splitting "boo:and:foo" yields:<br>
|
|
|
|
* <table border=0>
|
|
|
|
* <th><td>Regex</td> <td>Limit</td> <td>Result</td></th>
|
|
|
|
* <tr><td>":"</td> <td>2</td> <td>{ "boo", "and:foo" }</td></tr>
|
|
|
|
* <tr><td>":"</td> <td>t</td> <td>{ "boo", "and", "foo" }</td></tr>
|
|
|
|
* <tr><td>":"</td> <td>-2</td> <td>{ "boo", "and", "foo" }</td></tr>
|
|
|
|
* <tr><td>"o"</td> <td>5</td> <td>{ "b", "", ":and:f", "", "" }</td></tr>
|
|
|
|
* <tr><td>"o"</td> <td>-2</td> <td>{ "b", "", ":and:f", "", "" }</td></tr>
|
|
|
|
* <tr><td>"o"</td> <td>0</td> <td>{ "b", "", ":and:f" }</td></tr>
|
|
|
|
* </table>
|
|
|
|
*
|
|
|
|
* <p>This is shorthand for
|
|
|
|
* <code>{@link Pattern}.compile(regex).split(this, limit)</code>.
|
|
|
|
*
|
|
|
|
* @param regex the pattern to match
|
|
|
|
* @param limit the limit threshold
|
|
|
|
* @return the array of split strings
|
|
|
|
* @throws NullPointerException if regex or replacement is null
|
|
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
|
|
* @see Pattern#compile(String)
|
|
|
|
* @see Pattern#split(CharSequence, int)
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public String[] split(String regex, int limit)
|
|
|
|
{
|
|
|
|
return Pattern.compile(regex).split(this, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Split this string around the matches of a regular expression. Each
|
|
|
|
* element of the returned array is the largest block of characters not
|
|
|
|
* terminated by the regular expression, in the order the matches are found.
|
|
|
|
* The array length is unlimited, and trailing empty entries are discarded,
|
|
|
|
* as though calling <code>split(regex, 0)</code>.
|
|
|
|
*
|
|
|
|
* @param regex the pattern to match
|
|
|
|
* @return the array of split strings
|
|
|
|
* @throws NullPointerException if regex or replacement is null
|
|
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
|
|
* @see #split(String, int)
|
|
|
|
* @see Pattern#compile(String)
|
|
|
|
* @see Pattern#split(CharSequence, int)
|
|
|
|
* @since 1.4
|
|
|
|
*/
|
|
|
|
public String[] split(String regex)
|
|
|
|
{
|
|
|
|
return Pattern.compile(regex).split(this, 0);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Lowercases this String according to a particular locale. This uses
|
|
|
|
* Unicode's special case mappings, as applied to the given Locale, so the
|
|
|
|
* resulting string may be a different length.
|
|
|
|
*
|
|
|
|
* @param loc locale to use
|
|
|
|
* @return new lowercased String, or this if no characters were lowercased
|
|
|
|
* @throws NullPointerException if loc is null
|
|
|
|
* @see #toUpperCase(Locale)
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native String toLowerCase(Locale locale);
|
2000-11-18 03:29:13 +01:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Lowercases this String. This uses Unicode's special case mappings, as
|
|
|
|
* applied to the platform's default Locale, so the resulting string may
|
|
|
|
* be a different length.
|
|
|
|
*
|
|
|
|
* @return new lowercased String, or this if no characters were lowercased
|
|
|
|
* @see #toLowerCase(Locale)
|
|
|
|
* @see #toUpperCase()
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String toLowerCase()
|
2000-11-18 03:29:13 +01:00
|
|
|
{
|
|
|
|
// The JDK is a bit confused about what to do here. If we pass in
|
|
|
|
// the default Locale then special Locale handling might be
|
|
|
|
// invoked. However, the docs also say that Character.toLowerCase
|
|
|
|
// rules here. We go with the latter.
|
|
|
|
return toLowerCase (null);
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Uppercases this String according to a particular locale. This uses
|
|
|
|
* Unicode's special case mappings, as applied to the given Locale, so the
|
|
|
|
* resulting string may be a different length.
|
|
|
|
*
|
|
|
|
* @param loc locale to use
|
|
|
|
* @return new uppercased String, or this if no characters were uppercased
|
|
|
|
* @throws NullPointerException if loc is null
|
|
|
|
* @see #toLowerCase(Locale)
|
|
|
|
* @since 1.1
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native String toUpperCase(Locale locale);
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Uppercases this String. This uses Unicode's special case mappings, as
|
|
|
|
* applied to the platform's default Locale, so the resulting string may
|
|
|
|
* be a different length.
|
|
|
|
*
|
|
|
|
* @return new uppercased String, or this if no characters were uppercased
|
|
|
|
* @see #toUpperCase(Locale)
|
|
|
|
* @see #toLowerCase()
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String toUpperCase()
|
2000-11-18 03:29:13 +01:00
|
|
|
{
|
|
|
|
// The JDK is a bit confused about what to do here. If we pass in
|
|
|
|
// the default Locale then special Locale handling might be
|
|
|
|
// invoked. However, the docs also say that Character.toLowerCase
|
|
|
|
// rules here. We go with the latter.
|
|
|
|
return toUpperCase (null);
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Trims all characters less than or equal to <code>'\u0020'</code>
|
|
|
|
* (<code>' '</code>) from the beginning and end of this String. This
|
|
|
|
* includes many, but not all, ASCII control characters, and all
|
|
|
|
* {@link Character#whitespace(char)}.
|
|
|
|
*
|
|
|
|
* @return new trimmed String, or this if nothing trimmed
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native String trim();
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns this, as it is already a String!
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public String toString()
|
2003-03-30 07:38:28 +02:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the contents of this String into a character array. Subsequent
|
|
|
|
* changes to the array do not affect the String.
|
|
|
|
*
|
|
|
|
* @return character array copying the String
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native char[] toCharArray();
|
2003-03-30 07:38:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a String representation of an Object. This is "null" if the
|
|
|
|
* object is null, otherwise it is <code>obj.toString()</code> (which
|
|
|
|
* can be null).
|
|
|
|
*
|
|
|
|
* @param obj the Object
|
|
|
|
* @return the string conversion of obj
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static String valueOf(Object obj)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return obj == null ? "null" : obj.toString();
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representation of a character array. Subsequent
|
|
|
|
* changes to the array do not affect the String.
|
|
|
|
*
|
|
|
|
* @param data the character array
|
|
|
|
* @return a String containing the same character sequence as data
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @see #valueOf(char[], int, int)
|
|
|
|
* @see #String(char[])
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static String valueOf(char[] data)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return valueOf (data, 0, data.length);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing the character sequence of the char array,
|
|
|
|
* starting at the specified offset, and copying chars up to the specified
|
|
|
|
* count. Subsequent changes to the array do not affect the String.
|
|
|
|
*
|
|
|
|
* @param data character array
|
|
|
|
* @param offset position (base 0) to start copying out of data
|
|
|
|
* @param count the number of characters from data to copy
|
|
|
|
* @return String containing the chars from data[offset..offset+count]
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
2004-07-17 16:04:45 +02:00
|
|
|
* || offset + count > data.length)
|
2003-03-30 07:38:28 +02:00
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
* @see #String(char[], int, int)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static native String valueOf(char[] data, int offset, int count);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing the character sequence of the char array,
|
|
|
|
* starting at the specified offset, and copying chars up to the specified
|
|
|
|
* count. Subsequent changes to the array do not affect the String.
|
|
|
|
*
|
|
|
|
* @param data character array
|
|
|
|
* @param offset position (base 0) to start copying out of data
|
|
|
|
* @param count the number of characters from data to copy
|
|
|
|
* @return String containing the chars from data[offset..offset+count]
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
2004-07-17 16:04:45 +02:00
|
|
|
* || offset + count > data.length)
|
2003-03-30 07:38:28 +02:00
|
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
|
|
* @see #String(char[], int, int)
|
|
|
|
*/
|
|
|
|
public static String copyValueOf(char[] data, int offset, int count)
|
|
|
|
{
|
|
|
|
String r = new String ();
|
|
|
|
r.init(data, offset, count, false);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a String representation of a character array. Subsequent
|
|
|
|
* changes to the array do not affect the String.
|
|
|
|
*
|
|
|
|
* @param data the character array
|
|
|
|
* @return a String containing the same character sequence as data
|
|
|
|
* @throws NullPointerException if data is null
|
|
|
|
* @see #copyValueOf(char[], int, int)
|
|
|
|
* @see #String(char[])
|
|
|
|
*/
|
|
|
|
public static String copyValueOf(char[] data)
|
|
|
|
{
|
|
|
|
return copyValueOf (data, 0, data.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a String representing a boolean.
|
|
|
|
*
|
|
|
|
* @param b the boolean
|
|
|
|
* @return "true" if b is true, else "false"
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static String valueOf(boolean b)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return b ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing a character.
|
|
|
|
*
|
|
|
|
* @param c the character
|
|
|
|
* @return String containing the single character c
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static native String valueOf(char c);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing an integer.
|
|
|
|
*
|
|
|
|
* @param i the integer
|
|
|
|
* @return String containing the integer in base 10
|
|
|
|
* @see Integer#toString(int)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static native String valueOf(int i);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing a long.
|
|
|
|
*
|
|
|
|
* @param l the long
|
|
|
|
* @return String containing the long in base 10
|
|
|
|
* @see Long#toString(long)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static String valueOf(long l)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return Long.toString(l);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing a float.
|
|
|
|
*
|
|
|
|
* @param f the float
|
|
|
|
* @return String containing the float
|
|
|
|
* @see Float#toString(float)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static String valueOf(float f)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return Float.toString(f);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a String representing a double.
|
|
|
|
*
|
|
|
|
* @param d the double
|
|
|
|
* @return String containing the double
|
|
|
|
* @see Double#toString(double)
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public static String valueOf(double d)
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
|
|
|
return Double.toString(d);
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
/**
|
|
|
|
* Fetches this String from the intern hashtable. If two Strings are
|
|
|
|
* considered equal, by the equals() method, then intern() will return the
|
|
|
|
* same String instance. ie. if (s1.equals(s2)) then
|
|
|
|
* (s1.intern() == s2.intern()). All string literals and string-valued
|
|
|
|
* constant expressions are already interned.
|
|
|
|
*
|
|
|
|
* @return the interned String
|
|
|
|
*/
|
2003-03-30 23:14:32 +02:00
|
|
|
public native String intern();
|
1999-04-07 16:42:40 +02:00
|
|
|
|
Character.java (SIZE, [...]): New fields from Classpath.
* java/lang/Character.java (SIZE, MAX_CACHE, charCache,
MIN_SURROGATE, MAX_SURROGATE): New fields from Classpath.
(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE, MIN_LOW_SURROGATE,
MAX_LOW_SURROGATE): Javadoc fixes.
(valueOf, reverseBytes, isHighSurrogate, isLowSurrogate,
isSurrogatePair, toCodePoint, codePointAt, codePointBefore): New
methods from Classpath.
* java/lang/String.java (codePointAt, codePointBefore,
codePointCount, contains, replace): New methods from Classpath.
(contentEquals): Declare.
* java/lang/natString.cc (contentEquals): New method.
From-SVN: r109445
2006-01-07 01:46:28 +01:00
|
|
|
/**
|
|
|
|
* Return the number of code points between two indices in the
|
|
|
|
* <code>String</code>. An unpaired surrogate counts as a
|
|
|
|
* code point for this purpose. Characters outside the indicated
|
|
|
|
* range are not examined, even if the range ends in the middle of a
|
|
|
|
* surrogate pair.
|
|
|
|
*
|
|
|
|
* @param start the starting index
|
|
|
|
* @param end one past the ending index
|
|
|
|
* @return the number of code points
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public synchronized int codePointCount(int start, int end)
|
|
|
|
{
|
String.java, [...]: Merge from GNU Classpath HEAD.
2006-06-09 Thomas Fitzsimmons <fitzsim@redhat.com>
* java/lang/String.java, classpath/native/jni/classpath/jcl.h,
classpath/native/jni/qt-peer/eventmethods.h,
classpath/native/jni/qt-peer/qtmenupeer.cpp,
classpath/native/jni/qt-peer/.cvsignore,
classpath/native/jni/gtk-peer/gdkdisplay.h,
classpath/native/jni/gtk-peer/cairographics2d.h,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,
classpath/native/jni/gtk-peer/.cvsignore,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c,
classpath/native/jni/gtk-peer/gtkpeer.h,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c,
classpath/native/jni/gtk-peer/Makefile.am,
classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c,
classpath/native/jawt/Makefile.am,
classpath/native/jawt/.cvsignore,
classpath/native/target/Linux/Makefile.in,
classpath/native/plugin/gcjwebplugin.cc,
classpath/native/plugin/Makefile.am,
classpath/native/plugin/.cvsignore,
classpath/resource/Makefile.in,
classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java,
classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,
classpath/gnu/java/awt/peer/gtk/CairoSurface.java,
classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,
classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java,
classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,
classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java,
classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java,
classpath/gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java,
classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java,
classpath/gnu/java/awt/peer/gtk/GdkGraphics.java,
classpath/gnu/java/awt/peer/gtk/GtkToolkit.java,
classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java,
classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,
classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java,
classpath/gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java,
classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,
classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java,
classpath/gnu/java/awt/peer/gtk/GtkImage.java,
classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java,
classpath/gnu/java/awt/peer/gtk/GdkGlyphVector.java,
classpath/gnu/java/awt/peer/gtk/GtkCanvasPeer.java,
classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java,
classpath/gnu/java/awt/peer/swing/SwingComponent.java,
classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java,
classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java,
classpath/gnu/java/awt/peer/swing/SwingFramePeer.java,
classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java,
classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java,
classpath/gnu/java/awt/print/JavaPrinterJob.java,
classpath/gnu/java/awt/print/PostScriptGraphics2D.java,
classpath/gnu/java/awt/print/SpooledDocument.java,
classpath/gnu/java/awt/print/JavaPrinterGraphics.java,
classpath/gnu/java/awt/BitwiseXORComposite.java,
classpath/gnu/java/awt/font/GNUGlyphVector.java,
classpath/gnu/java/awt/font/opentype/NameDecoder.java,
classpath/gnu/java/awt/java2d/RasterGraphics.java,
classpath/gnu/java/awt/java2d/TexturePaintContext.java,
classpath/gnu/java/awt/java2d/PolyEdge.java,
classpath/gnu/java/awt/java2d/AbstractGraphics2D.java,
classpath/gnu/java/awt/java2d/AlphaCompositeContext.java,
classpath/gnu/java/awt/java2d/ImagePaint.java,
classpath/gnu/java/awt/Buffers.java,
classpath/gnu/classpath/Configuration.java.in,
classpath/gnu/javax/swing/text/html/CombinedAttributes.java,
classpath/gnu/javax/swing/text/html/CharacterAttributeTranslator.java,
classpath/gnu/javax/swing/text/html/parser/htmlAttributeSet.java,
classpath/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java,
classpath/gnu/javax/swing/text/html/ImageViewIconFactory.java,
classpath/tools/toolwrapper.c,
classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java,
classpath/tools/gnu/classpath/tools/native2ascii/Messages.java,
classpath/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java,
classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java,
classpath/tools/gnu/classpath/tools/getopt/OptionException.java,
classpath/tools/gnu/classpath/tools/getopt/Messages.java,
classpath/tools/gnu/classpath/tools/getopt/Option.java,
classpath/tools/gnu/classpath/tools/getopt/Parser.java,
classpath/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java,
classpath/tools/gnu/classpath/tools/jarsigner/JarSigner.java,
classpath/tools/gnu/classpath/tools/jarsigner/Main.java,
classpath/tools/gnu/classpath/tools/jarsigner/Messages.java,
classpath/tools/gnu/classpath/tools/jarsigner/package.html,
classpath/tools/gnu/classpath/tools/keytool/ListCmd.java,
classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java,
classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java,
classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java,
classpath/tools/gnu/classpath/tools/keytool/Messages.java,
classpath/tools/gnu/classpath/tools/keytool/package.html,
classpath/tools/gnu/classpath/tools/keytool/Command.java,
classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java,
classpath/tools/gnu/classpath/tools/keytool/Main.java,
classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java,
classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java,
classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java,
classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java,
classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java,
classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java,
classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java,
classpath/tools/gnu/classpath/tools/rmi/registry/package.html,
classpath/tools/gnu/classpath/tools/rmi/RMIC.txt,
classpath/tools/gnu/classpath/tools/rmi/RMIC.java,
classpath/tools/gnu/classpath/tools/appletviewer/ErrorApplet.java,
classpath/tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java,
classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java,
classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java,
classpath/tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java,
classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java,
classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java,
classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java,
classpath/tools/gnu/classpath/tools/appletviewer/AppletTag.java,
classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java,
classpath/tools/gnu/classpath/tools/appletviewer/Main.java,
classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java,
classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java,
classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java,
classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java,
classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java,
classpath/tools/gnu/classpath/tools/serialver/Messages.java,
classpath/tools/gnu/classpath/tools/serialver/SerialVer.java,
classpath/tools/gnu/classpath/tools/jar/Creator.java,
classpath/tools/gnu/classpath/tools/jar/Entry.java,
classpath/tools/gnu/classpath/tools/jar/Lister.java,
classpath/tools/gnu/classpath/tools/jar/Main.java,
classpath/tools/gnu/classpath/tools/jar/Updater.java,
classpath/tools/gnu/classpath/tools/jar/Messages.java,
classpath/tools/gnu/classpath/tools/jar/Extractor.java,
classpath/tools/gnu/classpath/tools/jar/Action.java,
classpath/tools/gnu/classpath/tools/jar/Indexer.java,
classpath/tools/gnu/classpath/tools/jar/WorkSet.java,
classpath/tools/gnu/classpath/tools/giop/GRMIC.txt,
classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java,
classpath/tools/gnu/classpath/tools/giop/GRMIC.java,
classpath/tools/Makefile.am, classpath/tools/jarsigner.in,
classpath/tools/keytool.in, classpath/tools/appletviewer.in,
classpath/tools/.cvsignore, classpath/configure.ac,
classpath/javax/swing/JTabbedPane.java,
classpath/javax/swing/AbstractButton.java,
classpath/javax/swing/JViewport.java,
classpath/javax/swing/KeyboardManager.java,
classpath/javax/swing/JMenuItem.java,
classpath/javax/swing/JMenuBar.java,
classpath/javax/swing/MenuSelectionManager.java,
classpath/javax/swing/JOptionPane.java,
classpath/javax/swing/JSpinner.java,
classpath/javax/swing/JCheckBoxMenuItem.java,
classpath/javax/swing/JEditorPane.java,
classpath/javax/swing/JFormattedTextField.java,
classpath/javax/swing/JTree.java,
classpath/javax/swing/CellRendererPane.java,
classpath/javax/swing/JScrollPane.java,
classpath/javax/swing/tree/VariableHeightLayoutCache.java,
classpath/javax/swing/tree/TreeNode.java,
classpath/javax/swing/tree/FixedHeightLayoutCache.java,
classpath/javax/swing/tree/DefaultTreeCellEditor.java,
classpath/javax/swing/tree/TreePath.java,
classpath/javax/swing/tree/RowMapper.java,
classpath/javax/swing/tree/DefaultMutableTreeNode.java,
classpath/javax/swing/tree/DefaultTreeModel.java,
classpath/javax/swing/tree/AbstractLayoutCache.java,
classpath/javax/swing/tree/TreeSelectionModel.java,
classpath/javax/swing/tree/DefaultTreeSelectionModel.java,
classpath/javax/swing/tree/DefaultTreeCellRenderer.java,
classpath/javax/swing/tree/ExpandVetoException.java,
classpath/javax/swing/JList.java,
classpath/javax/swing/table/JTableHeader.java,
classpath/javax/swing/table/AbstractTableModel.java,
classpath/javax/swing/table/DefaultTableModel.java,
classpath/javax/swing/table/TableCellEditor.java,
classpath/javax/swing/table/TableCellRenderer.java,
classpath/javax/swing/ProgressMonitor.java,
classpath/javax/swing/JToolBar.java,
classpath/javax/swing/TransferHandler.java,
classpath/javax/swing/DefaultCellEditor.java,
classpath/javax/swing/DefaultButtonModel.java,
classpath/javax/swing/JLayeredPane.java,
classpath/javax/swing/text/DefaultEditorKit.java,
classpath/javax/swing/text/DefaultCaret.java,
classpath/javax/swing/text/FieldView.java,
classpath/javax/swing/text/JTextComponent.java,
classpath/javax/swing/text/TextAction.java,
classpath/javax/swing/text/StyleContext.java,
classpath/javax/swing/text/html/HTMLDocument.java,
classpath/javax/swing/text/html/MinimalHTMLWriter.java,
classpath/javax/swing/text/html/ImageView.java,
classpath/javax/swing/text/html/HTMLEditorKit.java,
classpath/javax/swing/text/AbstractWriter.java,
classpath/javax/swing/text/GapContent.java,
classpath/javax/swing/text/Utilities.java,
classpath/javax/swing/text/PlainView.java,
classpath/javax/swing/UIManager.java,
classpath/javax/swing/JSplitPane.java,
classpath/javax/swing/JComponent.java,
classpath/javax/swing/SwingUtilities.java,
classpath/javax/swing/border/AbstractBorder.java,
classpath/javax/swing/border/CompoundBorder.java,
classpath/javax/swing/border/TitledBorder.java,
classpath/javax/swing/border/MatteBorder.java,
classpath/javax/swing/border/BevelBorder.java,
classpath/javax/swing/RepaintManager.java,
classpath/javax/swing/JTable.java,
classpath/javax/swing/UIDefaults.java,
classpath/javax/swing/DefaultDesktopManager.java,
classpath/javax/swing/JMenu.java,
classpath/javax/swing/JLabel.java,
classpath/javax/swing/JSlider.java,
classpath/javax/swing/plaf/basic/BasicToolBarUI.java,
classpath/javax/swing/plaf/basic/BasicButtonUI.java,
classpath/javax/swing/plaf/basic/BasicOptionPaneUI.java,
classpath/javax/swing/plaf/basic/BasicTextAreaUI.java,
classpath/javax/swing/plaf/basic/BasicToggleButtonUI.java,
classpath/javax/swing/plaf/basic/BasicSpinnerUI.java,
classpath/javax/swing/plaf/basic/BasicSliderUI.java,
classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java,
classpath/javax/swing/plaf/basic/BasicComboPopup.java,
classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java,
classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java,
classpath/javax/swing/plaf/basic/BasicProgressBarUI.java,
classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java,
classpath/javax/swing/plaf/basic/BasicPanelUI.java,
classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java,
classpath/javax/swing/plaf/basic/BasicTreeUI.java,
classpath/javax/swing/plaf/basic/BasicTableHeaderUI.java,
classpath/javax/swing/plaf/basic/BasicFileChooserUI.java,
classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java,
classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,
classpath/javax/swing/plaf/basic/BasicListUI.java,
classpath/javax/swing/plaf/basic/BasicIconFactory.java,
classpath/javax/swing/plaf/basic/BasicTextUI.java,
classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,
classpath/javax/swing/plaf/basic/BasicDirectoryModel.java,
classpath/javax/swing/plaf/basic/BasicRootPaneUI.java,
classpath/javax/swing/plaf/basic/BasicTableUI.java,
classpath/javax/swing/plaf/basic/SharedUIDefaults.java,
classpath/javax/swing/plaf/multi/MultiComboBoxUI.java,
classpath/javax/swing/plaf/multi/MultiListUI.java,
classpath/javax/swing/plaf/multi/MultiSplitPaneUI.java,
classpath/javax/swing/plaf/multi/MultiFileChooserUI.java,
classpath/javax/swing/plaf/multi/MultiOptionPaneUI.java,
classpath/javax/swing/plaf/multi/MultiTabbedPaneUI.java,
classpath/javax/swing/plaf/multi/MultiLookAndFeel.java,
classpath/javax/swing/plaf/metal/MetalSliderUI.java,
classpath/javax/swing/plaf/metal/MetalIconFactory.java,
classpath/javax/swing/plaf/metal/MetalComboBoxIcon.java,
classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java,
classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,
classpath/javax/swing/plaf/metal/MetalCheckBoxUI.java,
classpath/javax/swing/plaf/metal/MetalSeparatorUI.java,
classpath/javax/swing/plaf/metal/MetalBorders.java,
classpath/javax/swing/plaf/metal/MetalSplitPaneDivider.java,
classpath/javax/swing/plaf/metal/MetalScrollBarUI.java,
classpath/javax/swing/plaf/metal/MetalRootPaneUI.java,
classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java,
classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java,
classpath/javax/swing/plaf/metal/MetalToolTipUI.java,
classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java,
classpath/javax/swing/plaf/metal/MetalFileChooserUI.java,
classpath/javax/swing/plaf/metal/MetalUtils.java,
classpath/javax/swing/plaf/metal/MetalComboBoxButton.java,
classpath/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java,
classpath/javax/swing/plaf/metal/MetalButtonUI.java,
classpath/javax/swing/JPopupMenu.java,
classpath/javax/swing/JProgressBar.java,
classpath/javax/swing/WindowConstants.java,
classpath/javax/swing/JFrame.java,
classpath/javax/swing/JFileChooser.java,
classpath/javax/swing/JComboBox.java,
classpath/javax/swing/event/EventListenerList.java,
classpath/javax/swing/ListSelectionModel.java,
classpath/javax/swing/JScrollBar.java,
classpath/java/text/SimpleDateFormat.java,
classpath/java/text/NumberFormat.java,
classpath/java/text/class-dependencies.conf,
classpath/java/awt/image/ColorModel.java,
classpath/java/awt/image/BufferedImage.java,
classpath/java/awt/Window.java,
classpath/java/awt/ContainerOrderFocusTraversalPolicy.java,
classpath/java/awt/LightweightDispatcher.java,
classpath/java/awt/EventDispatchThread.java,
classpath/java/awt/BasicStroke.java,
classpath/java/awt/ColorPaintContext.java,
classpath/java/awt/Container.java,
classpath/java/awt/TexturePaint.java,
classpath/java/awt/Component.java, classpath/java/awt/Font.java,
classpath/java/awt/GraphicsConfiguration.java,
classpath/java/awt/DefaultKeyboardFocusManager.java,
classpath/java/awt/print/PrinterJob.java,
classpath/java/awt/im/InputContext.java,
classpath/java/awt/dnd/DragGestureRecognizer.java,
classpath/java/awt/Toolkit.java,
classpath/java/awt/font/GraphicAttribute.java,
classpath/java/awt/font/ImageGraphicAttribute.java,
classpath/java/awt/font/GlyphVector.java,
classpath/java/awt/font/GlyphMetrics.java,
classpath/java/awt/font/ShapeGraphicAttribute.java,
classpath/java/awt/Graphics2D.java,
classpath/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h,
classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h,
classpath/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h,
classpath/include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h,
classpath/include/gnu_java_awt_peer_gtk_GtkCanvasPeer.h,
classpath/include/config.h.in,
classpath/include/gnu_java_awt_peer_gtk_GdkTextLayout.h,
classpath/include/gnu_java_awt_peer_gtk_GtkComponentPeer.h,
classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h,
classpath/include/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h,
classpath/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h,
classpath/include/gnu_java_awt_peer_gtk_GtkImage.h,
classpath/include/gnu_java_awt_peer_gtk_CairoSurface.h,
classpath/include/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h:
Merge from GNU Classpath HEAD.
From-SVN: r114510
2006-06-09 18:07:07 +02:00
|
|
|
if (start < 0 || end > count || start > end)
|
Character.java (SIZE, [...]): New fields from Classpath.
* java/lang/Character.java (SIZE, MAX_CACHE, charCache,
MIN_SURROGATE, MAX_SURROGATE): New fields from Classpath.
(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE, MIN_LOW_SURROGATE,
MAX_LOW_SURROGATE): Javadoc fixes.
(valueOf, reverseBytes, isHighSurrogate, isLowSurrogate,
isSurrogatePair, toCodePoint, codePointAt, codePointBefore): New
methods from Classpath.
* java/lang/String.java (codePointAt, codePointBefore,
codePointCount, contains, replace): New methods from Classpath.
(contentEquals): Declare.
* java/lang/natString.cc (contentEquals): New method.
From-SVN: r109445
2006-01-07 01:46:28 +01:00
|
|
|
throw new StringIndexOutOfBoundsException();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
while (start < end)
|
|
|
|
{
|
|
|
|
char base = charAt(start);
|
|
|
|
if (base < Character.MIN_HIGH_SURROGATE
|
|
|
|
|| base > Character.MAX_HIGH_SURROGATE
|
|
|
|
|| start == end
|
|
|
|
|| start == count
|
|
|
|
|| charAt(start + 1) < Character.MIN_LOW_SURROGATE
|
|
|
|
|| charAt(start + 1) > Character.MAX_LOW_SURROGATE)
|
|
|
|
{
|
|
|
|
// Nothing.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Surrogate pair.
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
++start;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true iff this String contains the sequence of Characters
|
|
|
|
* described in s.
|
|
|
|
* @param s the CharSequence
|
|
|
|
* @return true iff this String contains s
|
|
|
|
*
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public boolean contains (CharSequence s)
|
|
|
|
{
|
|
|
|
return this.indexOf(s.toString()) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string that is this string with all instances of the sequence
|
|
|
|
* represented by <code>target</code> replaced by the sequence in
|
|
|
|
* <code>replacement</code>.
|
|
|
|
* @param target the sequence to be replaced
|
|
|
|
* @param replacement the sequence used as the replacement
|
|
|
|
* @return the string constructed as above
|
|
|
|
*/
|
|
|
|
public String replace (CharSequence target, CharSequence replacement)
|
|
|
|
{
|
|
|
|
String targetString = target.toString();
|
|
|
|
String replaceString = replacement.toString();
|
|
|
|
int targetLength = target.length();
|
|
|
|
int replaceLength = replacement.length();
|
|
|
|
|
|
|
|
int startPos = this.indexOf(targetString);
|
|
|
|
StringBuilder result = new StringBuilder(this);
|
|
|
|
while (startPos != -1)
|
|
|
|
{
|
|
|
|
// Replace the target with the replacement
|
|
|
|
result.replace(startPos, startPos + targetLength, replaceString);
|
|
|
|
|
|
|
|
// Search for a new occurrence of the target
|
|
|
|
startPos = result.indexOf(targetString, startPos + replaceLength);
|
|
|
|
}
|
|
|
|
return result.toString();
|
|
|
|
}
|
|
|
|
|
2003-03-30 07:38:28 +02:00
|
|
|
|
2003-03-30 23:14:32 +02:00
|
|
|
private native void init(char[] chars, int offset, int count,
|
|
|
|
boolean dont_copy);
|
|
|
|
private native void init(byte[] chars, int hibyte, int offset, int count);
|
|
|
|
private native void init(byte[] chars, int offset, int count, String enc)
|
1999-04-07 16:42:40 +02:00
|
|
|
throws UnsupportedEncodingException;
|
2003-07-28 18:12:00 +02:00
|
|
|
private native void init(gnu.gcj.runtime.StringBuffer buffer);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|