Commit 666ff4f6 by Mark Wielaard Committed by Tom Tromey

Character.java: Re-merged with Classpath.

2007-03-05  Mark Wielaard  <mark@klomp.org>

	* java/lang/Character.java: Re-merged with Classpath.
	* java/lang/natString.cc (nativeCompareTo): Renamed from
	compareTo.
	* java/lang/StringBuilder.java: Re-merged with Classpath.
	* java/lang/String.java: Re-merged with Classpath.
	(nativeCompareTo): Renamed from compareTo.
	* java/lang/StringBuffer.java: Re-merged with Classpath.
	* jni.cc (_Jv_JNI_GetAnyMethodID): Split calls to append.

From-SVN: r122560
parent b48a4592
2007-03-05 Mark Wielaard <mark@klomp.org>
* java/lang/Character.java: Re-merged with Classpath.
* java/lang/natString.cc (nativeCompareTo): Renamed from
compareTo.
* java/lang/StringBuilder.java: Re-merged with Classpath.
* java/lang/String.java: Re-merged with Classpath.
(nativeCompareTo): Renamed from compareTo.
* java/lang/StringBuffer.java: Re-merged with Classpath.
* jni.cc (_Jv_JNI_GetAnyMethodID): Split calls to append.
2007-03-05 Andrew Haley <aph@redhat.com> 2007-03-05 Andrew Haley <aph@redhat.com>
* java/lang/reflect/natVMProxy.cc (ncode_closure.meth): Delete. * java/lang/reflect/natVMProxy.cc (ncode_closure.meth): Delete.
......
// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-
#ifndef __java_lang_Character$UnicodeBlock$NameType__
#define __java_lang_Character$UnicodeBlock$NameType__
#pragma interface
#include <java/lang/Enum.h>
#include <gcj/array.h>
class java::lang::Character$UnicodeBlock$NameType : public ::java::lang::Enum
{
Character$UnicodeBlock$NameType(::java::lang::String *, jint);
public:
static JArray< ::java::lang::Character$UnicodeBlock$NameType * > * values();
static ::java::lang::Character$UnicodeBlock$NameType * valueOf(::java::lang::String *);
static ::java::lang::Character$UnicodeBlock$NameType * CANONICAL;
static ::java::lang::Character$UnicodeBlock$NameType * NO_SPACES;
static ::java::lang::Character$UnicodeBlock$NameType * CONSTANT;
private:
static JArray< ::java::lang::Character$UnicodeBlock$NameType * > * ENUM$VALUES;
public:
static ::java::lang::Class class$;
};
#endif // __java_lang_Character$UnicodeBlock$NameType__
...@@ -18,13 +18,12 @@ public: ...@@ -18,13 +18,12 @@ public:
static ::java::lang::Character$UnicodeBlock * of(jchar); static ::java::lang::Character$UnicodeBlock * of(jchar);
static ::java::lang::Character$UnicodeBlock * of(jint); static ::java::lang::Character$UnicodeBlock * of(jint);
static ::java::lang::Character$UnicodeBlock * forName(::java::lang::String *); static ::java::lang::Character$UnicodeBlock * forName(::java::lang::String *);
public: // actually package-private
static JArray< jint > * $SWITCH_TABLE$java$lang$Character$UnicodeBlock$NameType();
private: private:
jint __attribute__((aligned(__alignof__( ::java::lang::Character$Subset)))) start; jint __attribute__((aligned(__alignof__( ::java::lang::Character$Subset)))) start;
jint end; jint end;
::java::lang::String * canonicalName; ::java::lang::String * canonicalName;
static const jint CANONICAL_NAME = 0;
static const jint NO_SPACES_NAME = 1;
static const jint CONSTANT_NAME = 2;
public: public:
static ::java::lang::Character$UnicodeBlock * BASIC_LATIN; static ::java::lang::Character$UnicodeBlock * BASIC_LATIN;
static ::java::lang::Character$UnicodeBlock * LATIN_1_SUPPLEMENT; static ::java::lang::Character$UnicodeBlock * LATIN_1_SUPPLEMENT;
...@@ -154,6 +153,7 @@ public: ...@@ -154,6 +153,7 @@ public:
static ::java::lang::Character$UnicodeBlock * SURROGATES_AREA; static ::java::lang::Character$UnicodeBlock * SURROGATES_AREA;
private: private:
static JArray< ::java::lang::Character$UnicodeBlock * > * sets; static JArray< ::java::lang::Character$UnicodeBlock * > * sets;
static JArray< jint > * $SWITCH_TABLE$java$lang$Character$UnicodeBlock$NameType__;
public: public:
static ::java::lang::Class class$; static ::java::lang::Class class$;
}; };
......
...@@ -34,6 +34,10 @@ public: ...@@ -34,6 +34,10 @@ public:
static jboolean isDefined(jint); static jboolean isDefined(jint);
static jboolean isLetter(jchar); static jboolean isLetter(jchar);
static jboolean isLetter(jint); static jboolean isLetter(jint);
static jint offsetByCodePoints(::java::lang::CharSequence *, jint, jint);
static jint offsetByCodePoints(JArray< jchar > *, jint, jint, jint, jint);
static jint codePointCount(::java::lang::CharSequence *, jint, jint);
static jint codePointCount(JArray< jchar > *, jint, jint);
static jboolean isLetterOrDigit(jchar); static jboolean isLetterOrDigit(jchar);
static jboolean isLetterOrDigit(jint); static jboolean isLetterOrDigit(jint);
static jboolean isJavaLetter(jchar); static jboolean isJavaLetter(jchar);
...@@ -72,8 +76,7 @@ public: ...@@ -72,8 +76,7 @@ public:
static jbyte getDirectionality(jint); static jbyte getDirectionality(jint);
static jboolean isMirrored(jchar); static jboolean isMirrored(jchar);
static jboolean isMirrored(jint); static jboolean isMirrored(jint);
jint compareTo(::java::lang::Character *); jint target$compareTo(::java::lang::Character *);
jint compareTo(::java::lang::Object *);
static ::java::lang::Character * valueOf(jchar); static ::java::lang::Character * valueOf(jchar);
static jchar reverseBytes(jchar); static jchar reverseBytes(jchar);
static JArray< jchar > * toChars(jint); static JArray< jchar > * toChars(jint);
...@@ -91,6 +94,7 @@ public: ...@@ -91,6 +94,7 @@ public:
static jint codePointBefore(JArray< jchar > *, jint); static jint codePointBefore(JArray< jchar > *, jint);
static jint codePointBefore(JArray< jchar > *, jint, jint); static jint codePointBefore(JArray< jchar > *, jint, jint);
static jint codePointBefore(::java::lang::CharSequence *, jint); static jint codePointBefore(::java::lang::CharSequence *, jint);
jint compareTo(::java::lang::Object *);
private: private:
jchar __attribute__((aligned(__alignof__( ::java::lang::Object)))) value; jchar __attribute__((aligned(__alignof__( ::java::lang::Object)))) value;
static const jlong serialVersionUID = 3786198910865385080LL; static const jlong serialVersionUID = 3786198910865385080LL;
...@@ -99,6 +103,15 @@ public: ...@@ -99,6 +103,15 @@ public:
static const jint MAX_RADIX = 36; static const jint MAX_RADIX = 36;
static const jchar MIN_VALUE = 0; static const jchar MIN_VALUE = 0;
static const jchar MAX_VALUE = 65535; static const jchar MAX_VALUE = 65535;
static const jint MIN_CODE_POINT = 0;
static const jint MAX_CODE_POINT = 1114111;
static const jchar MIN_HIGH_SURROGATE = 55296;
static const jchar MAX_HIGH_SURROGATE = 56319;
static const jchar MIN_LOW_SURROGATE = 56320;
static const jchar MAX_LOW_SURROGATE = 57343;
static const jchar MIN_SURROGATE = 55296;
static const jchar MAX_SURROGATE = 57343;
static const jint MIN_SUPPLEMENTARY_CODE_POINT = 65536;
static ::java::lang::Class * TYPE; static ::java::lang::Class * TYPE;
static const jint SIZE = 16; static const jint SIZE = 16;
private: private:
...@@ -160,15 +173,6 @@ private: ...@@ -160,15 +173,6 @@ private:
static const jint NO_BREAK_MASK = 32; static const jint NO_BREAK_MASK = 32;
static const jint MIRROR_MASK = 64; static const jint MIRROR_MASK = 64;
public: public:
static const jint MIN_SUPPLEMENTARY_CODE_POINT = 65536;
static const jint MIN_CODE_POINT = 0;
static const jint MAX_CODE_POINT = 1114111;
static const jchar MIN_HIGH_SURROGATE = 55296;
static const jchar MAX_HIGH_SURROGATE = 56319;
static const jchar MIN_LOW_SURROGATE = 56320;
static const jchar MAX_LOW_SURROGATE = 57343;
static const jchar MIN_SURROGATE = 55296;
static const jchar MAX_SURROGATE = 57343;
static ::java::lang::Class class$; static ::java::lang::Class class$;
}; };
......
...@@ -14,6 +14,7 @@ class java::lang::String$CaseInsensitiveComparator : public ::java::lang::Object ...@@ -14,6 +14,7 @@ class java::lang::String$CaseInsensitiveComparator : public ::java::lang::Object
public: // actually package-private public: // actually package-private
String$CaseInsensitiveComparator(); String$CaseInsensitiveComparator();
public: public:
jint target$compare(::java::lang::String *, ::java::lang::String *);
jint compare(::java::lang::Object *, ::java::lang::Object *); jint compare(::java::lang::Object *, ::java::lang::Object *);
private: private:
static const jlong serialVersionUID = 8575799808933029326LL; static const jlong serialVersionUID = 8575799808933029326LL;
......
...@@ -62,8 +62,10 @@ public: ...@@ -62,8 +62,10 @@ public:
jboolean contentEquals(::java::lang::StringBuffer *); jboolean contentEquals(::java::lang::StringBuffer *);
jboolean contentEquals(::java::lang::CharSequence *); jboolean contentEquals(::java::lang::CharSequence *);
jboolean equalsIgnoreCase(::java::lang::String *); jboolean equalsIgnoreCase(::java::lang::String *);
jint compareTo(::java::lang::String *); jint target$compareTo(::java::lang::String *);
jint compareTo(::java::lang::Object *); private:
jint nativeCompareTo(::java::lang::String *);
public:
jint compareToIgnoreCase(::java::lang::String *); jint compareToIgnoreCase(::java::lang::String *);
jboolean regionMatches(jint, ::java::lang::String *, jint, jint); jboolean regionMatches(jint, ::java::lang::String *, jint, jint);
jboolean regionMatches(jboolean, jint, ::java::lang::String *, jint, jint); jboolean regionMatches(jboolean, jint, ::java::lang::String *, jint, jint);
...@@ -107,15 +109,22 @@ public: ...@@ -107,15 +109,22 @@ public:
static ::java::lang::String * valueOf(jlong); static ::java::lang::String * valueOf(jlong);
static ::java::lang::String * valueOf(jfloat); static ::java::lang::String * valueOf(jfloat);
static ::java::lang::String * valueOf(jdouble); static ::java::lang::String * valueOf(jdouble);
static ::java::lang::String * format(::java::util::Locale *, ::java::lang::String *, JArray< ::java::lang::Object * > *);
static ::java::lang::String * format(::java::lang::String *, JArray< ::java::lang::Object * > *);
::java::lang::String * intern(); ::java::lang::String * intern();
jint codePointCount(jint, jint); jint codePointCount(jint, jint);
jboolean contains(::java::lang::CharSequence *); jboolean contains(::java::lang::CharSequence *);
::java::lang::String * replace(::java::lang::CharSequence *, ::java::lang::CharSequence *); ::java::lang::String * replace(::java::lang::CharSequence *, ::java::lang::CharSequence *);
jint offsetByCodePoints(jint, jint);
jboolean isEmpty();
private: private:
void init(JArray< jchar > *, jint, jint, jboolean); void init(JArray< jchar > *, jint, jint, jboolean);
void init(JArray< jbyte > *, jint, jint, jint); void init(JArray< jbyte > *, jint, jint, jint);
void init(JArray< jbyte > *, jint, jint, ::java::lang::String *); void init(JArray< jbyte > *, jint, jint, ::java::lang::String *);
void init(::gnu::gcj::runtime::StringBuffer *); void init(::gnu::gcj::runtime::StringBuffer *);
public:
jint compareTo(::java::lang::Object *);
private:
static const jlong serialVersionUID = -6849794470754667710LL; static const jlong serialVersionUID = -6849794470754667710LL;
::java::lang::Object * __attribute__((aligned(__alignof__( ::java::lang::Object)))) data; ::java::lang::Object * __attribute__((aligned(__alignof__( ::java::lang::Object)))) data;
jint boffset; jint boffset;
......
/* String.java -- immutable character sequences; the object of string literals /* String.java -- immutable character sequences; the object of string literals
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -41,9 +41,11 @@ package java.lang; ...@@ -41,9 +41,11 @@ package java.lang;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.Comparable;
import java.util.Comparator; import java.util.Comparator;
import java.text.Collator;
import java.util.Formatter;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
...@@ -70,10 +72,13 @@ import java.util.regex.PatternSyntaxException; ...@@ -70,10 +72,13 @@ import java.util.regex.PatternSyntaxException;
* @author Paul N. Fisher * @author Paul N. Fisher
* @author Eric Blake (ebb9@email.byu.edu) * @author Eric Blake (ebb9@email.byu.edu)
* @author Per Bothner (bothner@cygnus.com) * @author Per Bothner (bothner@cygnus.com)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0 * @since 1.0
* @status updated to 1.4 * @status updated to 1.4
*/ */
public final class String implements Serializable, Comparable, CharSequence public final class String
implements Serializable, Comparable<String>, CharSequence
{ {
// WARNING: String is a CORE class in the bootstrap cycle. See the comments // WARNING: String is a CORE class in the bootstrap cycle. See the comments
// in vm/reference/java/lang/Runtime for implications of this fact. // in vm/reference/java/lang/Runtime for implications of this fact.
...@@ -113,12 +118,12 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -113,12 +118,12 @@ public final class String implements Serializable, Comparable, CharSequence
private int cachedHashCode; private int cachedHashCode;
/** /**
* An implementation for {@link CASE_INSENSITIVE_ORDER}. * An implementation for {@link #CASE_INSENSITIVE_ORDER}.
* This must be {@link Serializable}. The class name is dictated by * This must be {@link Serializable}. The class name is dictated by
* compatibility with Sun's JDK. * compatibility with Sun's JDK.
*/ */
private static final class CaseInsensitiveComparator private static final class CaseInsensitiveComparator
implements Comparator, Serializable implements Comparator<String>, Serializable
{ {
/** /**
* Compatible with JDK 1.2. * Compatible with JDK 1.2.
...@@ -142,9 +147,9 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -142,9 +147,9 @@ public final class String implements Serializable, Comparable, CharSequence
* @throws ClassCastException if either argument is not a String * @throws ClassCastException if either argument is not a String
* @see #compareToIgnoreCase(String) * @see #compareToIgnoreCase(String)
*/ */
public int compare(Object o1, Object o2) public int compare(String o1, String o2)
{ {
return ((String) o1).compareToIgnoreCase((String) o2); return o1.compareToIgnoreCase(o2);
} }
} // class CaseInsensitiveComparator } // class CaseInsensitiveComparator
...@@ -156,7 +161,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -156,7 +161,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @see Collator#compare(String, String) * @see Collator#compare(String, String)
* @since 1.2 * @since 1.2
*/ */
public static final Comparator CASE_INSENSITIVE_ORDER public static final Comparator<String> CASE_INSENSITIVE_ORDER
= new CaseInsensitiveComparator(); = new CaseInsensitiveComparator();
/** /**
...@@ -207,6 +212,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -207,6 +212,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @param count the number of characters from data to copy * @param count the number of characters from data to copy
* @throws NullPointerException if data is null * @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0 * @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
* || offset + count &lt; 0 (overflow)
* || offset + count &gt; data.length) * || offset + count &gt; data.length)
* (while unspecified, this is a StringIndexOutOfBoundsException) * (while unspecified, this is a StringIndexOutOfBoundsException)
*/ */
...@@ -230,6 +236,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -230,6 +236,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @param count the number of characters from ascii to copy * @param count the number of characters from ascii to copy
* @throws NullPointerException if ascii is null * @throws NullPointerException if ascii is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0 * @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
* || offset + count &lt; 0 (overflow)
* || offset + count &gt; ascii.length) * || offset + count &gt; ascii.length)
* (while unspecified, this is a StringIndexOutOfBoundsException) * (while unspecified, this is a StringIndexOutOfBoundsException)
* @see #String(byte[]) * @see #String(byte[])
...@@ -281,7 +288,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -281,7 +288,7 @@ public final class String implements Serializable, Comparable, CharSequence
* *
* @param data byte array to copy * @param data byte array to copy
* @param offset the offset to start at * @param offset the offset to start at
* @param count the number of characters in the array to use * @param count the number of bytes in the array to use
* @param encoding the name of the encoding to use * @param encoding the name of the encoding to use
* @throws NullPointerException if data or encoding is null * @throws NullPointerException if data or encoding is null
* @throws IndexOutOfBoundsException if offset or count is incorrect * @throws IndexOutOfBoundsException if offset or count is incorrect
...@@ -330,7 +337,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -330,7 +337,7 @@ public final class String implements Serializable, Comparable, CharSequence
* *
* @param data byte array to copy * @param data byte array to copy
* @param offset the offset to start at * @param offset the offset to start at
* @param count the number of characters in the array to use * @param count the number of bytes in the array to use
* @throws NullPointerException if data is null * @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if offset or count is incorrect * @throws IndexOutOfBoundsException if offset or count is incorrect
* @throws Error if the decoding fails * @throws Error if the decoding fails
...@@ -644,23 +651,17 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -644,23 +651,17 @@ public final class String implements Serializable, Comparable, CharSequence
* @return the comparison * @return the comparison
* @throws NullPointerException if anotherString is null * @throws NullPointerException if anotherString is null
*/ */
public native int compareTo(String anotherString); public int compareTo(String anotherString)
{
return nativeCompareTo(anotherString);
}
/** /**
* Behaves like <code>compareTo(java.lang.String)</code> unless the Object * The native implementation of compareTo(). Must be named different
* is not a <code>String</code>. Then it throws a * since cni doesn't understand the bridge method generated from
* <code>ClassCastException</code>. * the compareTo() method because of the Comparable<String> interface.
*
* @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) private native int nativeCompareTo(String anotherString);
{
return compareTo((String) o);
}
/** /**
* Compares this String and another String (case insensitive). This * Compares this String and another String (case insensitive). This
...@@ -710,7 +711,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -710,7 +711,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @param ignoreCase true if case should be ignored in comparision * @param ignoreCase true if case should be ignored in comparision
* @param toffset index to start comparison at for this String * @param toffset index to start comparison at for this String
* @param other String to compare region to this String * @param other String to compare region to this String
* @param oofset index to start comparison at for other * @param ooffset index to start comparison at for other
* @param len number of characters to compare * @param len number of characters to compare
* @return true if regions match, false otherwise * @return true if regions match, false otherwise
* @throws NullPointerException if other is null * @throws NullPointerException if other is null
...@@ -1124,7 +1125,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -1124,7 +1125,7 @@ public final class String implements Serializable, Comparable, CharSequence
* Trims all characters less than or equal to <code>'\u0020'</code> * Trims all characters less than or equal to <code>'\u0020'</code>
* (<code>' '</code>) from the beginning and end of this String. This * (<code>' '</code>) from the beginning and end of this String. This
* includes many, but not all, ASCII control characters, and all * includes many, but not all, ASCII control characters, and all
* {@link Character#whitespace(char)}. * {@link Character#isWhitespace(char)}.
* *
* @return new trimmed String, or this if nothing trimmed * @return new trimmed String, or this if nothing trimmed
*/ */
...@@ -1204,6 +1205,7 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -1204,6 +1205,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @return String containing the chars from data[offset..offset+count] * @return String containing the chars from data[offset..offset+count]
* @throws NullPointerException if data is null * @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0 * @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
* || offset + count &lt; 0 (overflow)
* || offset + count &gt; data.length) * || offset + count &gt; data.length)
* (while unspecified, this is a StringIndexOutOfBoundsException) * (while unspecified, this is a StringIndexOutOfBoundsException)
* @see #String(char[], int, int) * @see #String(char[], int, int)
...@@ -1294,12 +1296,27 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -1294,12 +1296,27 @@ public final class String implements Serializable, Comparable, CharSequence
return Double.toString(d); return Double.toString(d);
} }
/** @since 1.5 */
public static String format(Locale locale, String format, Object... args)
{
Formatter f = new Formatter(locale);
return f.format(format, args).toString();
}
/** @since 1.5 */
public static String format(String format, Object... args)
{
return format(Locale.getDefault(), format, args);
}
/** /**
* Fetches this String from the intern hashtable. If two Strings are * Fetches this String from the intern hashtable.
* considered equal, by the equals() method, then intern() will return the * If two Strings are considered equal, by the equals() method,
* same String instance. ie. if (s1.equals(s2)) then * then intern() will return the same String instance. ie.
* (s1.intern() == s2.intern()). All string literals and string-valued * if (s1.equals(s2)) then (s1.intern() == s2.intern()).
* constant expressions are already interned. * All string literals and string-valued constant expressions
* are already interned.
* *
* @return the interned String * @return the interned String
*/ */
...@@ -1387,6 +1404,41 @@ public final class String implements Serializable, Comparable, CharSequence ...@@ -1387,6 +1404,41 @@ public final class String implements Serializable, Comparable, CharSequence
return result.toString(); return result.toString();
} }
/**
* Return the index into this String that is offset from the given index by
* <code>codePointOffset</code> code points.
* @param index the index at which to start
* @param codePointOffset the number of code points to offset
* @return the index into this String that is <code>codePointOffset</code>
* code points offset from <code>index</code>.
*
* @throws IndexOutOfBoundsException if index is negative or larger than the
* length of this string.
* @throws IndexOutOfBoundsException if codePointOffset is positive and the
* substring starting with index has fewer than codePointOffset code points.
* @throws IndexOutOfBoundsException if codePointOffset is negative and the
* substring ending with index has fewer than (-codePointOffset) code points.
* @since 1.5
*/
public int offsetByCodePoints(int index, int codePointOffset)
{
if (index < 0 || index > count)
throw new IndexOutOfBoundsException();
return Character.offsetByCodePoints(this, index, codePointOffset);
}
/**
* Returns true if, and only if, {@link #length()}
* is <code>0</code>.
*
* @return true if the length of the string is zero.
* @since 1.6
*/
public boolean isEmpty()
{
return count == 0;
}
private native void init(char[] chars, int offset, int count, private native void init(char[] chars, int offset, int count,
boolean dont_copy); boolean dont_copy);
......
...@@ -30,13 +30,13 @@ public: ...@@ -30,13 +30,13 @@ public:
::java::lang::StringBuffer * append(::java::lang::Object *); ::java::lang::StringBuffer * append(::java::lang::Object *);
::java::lang::StringBuffer * append(::java::lang::String *); ::java::lang::StringBuffer * append(::java::lang::String *);
::java::lang::StringBuffer * append(::java::lang::StringBuffer *); ::java::lang::StringBuffer * append(::java::lang::StringBuffer *);
::java::lang::StringBuffer * append(::java::lang::CharSequence *);
::java::lang::StringBuffer * append(::java::lang::CharSequence *, jint, jint);
::java::lang::StringBuffer * append(JArray< jchar > *); ::java::lang::StringBuffer * append(JArray< jchar > *);
::java::lang::StringBuffer * append(JArray< jchar > *, jint, jint); ::java::lang::StringBuffer * append(JArray< jchar > *, jint, jint);
::java::lang::StringBuffer * append(jboolean);
::java::lang::StringBuffer * append(jchar);
::java::lang::StringBuffer * appendCodePoint(jint); ::java::lang::StringBuffer * appendCodePoint(jint);
::java::lang::StringBuffer * append(jboolean);
::java::lang::StringBuffer * target$append(jchar);
::java::lang::StringBuffer * target$append(::java::lang::CharSequence *);
::java::lang::StringBuffer * target$append(::java::lang::CharSequence *, jint, jint);
::java::lang::StringBuffer * append(jint); ::java::lang::StringBuffer * append(jint);
::java::lang::StringBuffer * append(jlong); ::java::lang::StringBuffer * append(jlong);
::java::lang::StringBuffer * append(jfloat); ::java::lang::StringBuffer * append(jfloat);
...@@ -71,6 +71,11 @@ public: ...@@ -71,6 +71,11 @@ public:
private: private:
void ensureCapacity_unsynchronized(jint); void ensureCapacity_unsynchronized(jint);
jboolean regionMatches(jint, ::java::lang::String *); jboolean regionMatches(jint, ::java::lang::String *);
public:
::java::lang::Appendable * append(::java::lang::CharSequence *, jint, jint);
::java::lang::Appendable * append(::java::lang::CharSequence *);
::java::lang::Appendable * append(jchar);
private:
static const jlong serialVersionUID = 3388685877147921107LL; static const jlong serialVersionUID = 3388685877147921107LL;
public: // actually package-private public: // actually package-private
jint __attribute__((aligned(__alignof__( ::java::lang::Object)))) count; jint __attribute__((aligned(__alignof__( ::java::lang::Object)))) count;
......
/* StringBuffer.java -- Growable strings /* StringBuffer.java -- Growable strings
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -72,8 +72,12 @@ import java.io.Serializable; ...@@ -72,8 +72,12 @@ import java.io.Serializable;
* @since 1.0 * @since 1.0
* @status updated to 1.4 * @status updated to 1.4
*/ */
public final class StringBuffer implements Serializable, CharSequence public final class StringBuffer
implements Serializable, CharSequence, Appendable
{ {
// Implementation note: if you change this class, you usually will
// want to change StringBuilder as well.
/** /**
* Compatible with JDK 1.0+. * Compatible with JDK 1.0+.
*/ */
...@@ -152,17 +156,16 @@ public final class StringBuffer implements Serializable, CharSequence ...@@ -152,17 +156,16 @@ public final class StringBuffer implements Serializable, CharSequence
* specified <code>CharSequence</code>. Initial capacity will be the * specified <code>CharSequence</code>. Initial capacity will be the
* size of the CharSequence plus 16. * size of the CharSequence plus 16.
* *
* @param sequence the <code>String</code> to convert * @param seq the <code>String</code> to convert
* @throws NullPointerException if str is null * @throws NullPointerException if str is null
*
* @since 1.5 * @since 1.5
*/ */
public StringBuffer(CharSequence sequence) public StringBuffer(CharSequence seq)
{ {
count = Math.max(0, sequence.length()); count = Math.max(0, seq.length());
value = new char[count + DEFAULT_CAPACITY]; value = new char[count + DEFAULT_CAPACITY];
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
value[i] = sequence.charAt(i); value[i] = seq.charAt(i);
} }
/** /**
...@@ -391,46 +394,6 @@ public final class StringBuffer implements Serializable, CharSequence ...@@ -391,46 +394,6 @@ public final class StringBuffer implements Serializable, CharSequence
} }
/** /**
* Append the <code>CharSequence</code> value of the argument to this
* <code>StringBuffer</code>.
*
* @param sequence the <code>CharSequence</code> to append
* @return this <code>StringBuffer</code>
* @see #append(Object)
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence sequence)
{
if (sequence == null)
sequence = "null";
return append(sequence, 0, sequence.length());
}
/**
* Append the specified subsequence of the <code>CharSequence</code>
* argument to this <code>StringBuffer</code>.
*
* @param sequence the <code>CharSequence</code> to append
* @param start the starting index
* @param end one past the ending index
* @return this <code>StringBuffer</code>
* @see #append(Object)
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence sequence,
int start, int end)
{
if (sequence == null)
sequence = "null";
if (start < 0 || end < 0 || start > end || end > sequence.length())
throw new IndexOutOfBoundsException();
ensureCapacity_unsynchronized(this.count + end - start);
for (int i = start; i < end; ++i)
value[count++] = sequence.charAt(i);
return this;
}
/**
* Append the <code>char</code> array to this <code>StringBuffer</code>. * Append the <code>char</code> array to this <code>StringBuffer</code>.
* This is similar (but more efficient) than * This is similar (but more efficient) than
* <code>append(new String(data))</code>, except in the case of null. * <code>append(new String(data))</code>, except in the case of null.
...@@ -470,6 +433,25 @@ public final class StringBuffer implements Serializable, CharSequence ...@@ -470,6 +433,25 @@ public final class StringBuffer implements Serializable, CharSequence
} }
/** /**
* Append the code point to this <code>StringBuffer</code>.
* This is like #append(char), but will append two characters
* if a supplementary code point is given.
*
* @param code the code point to append
* @return this <code>StringBuffer</code>
* @see Character#toChars(int, char[], int)
* @since 1.5
*/
public synchronized StringBuffer appendCodePoint(int code)
{
int len = Character.charCount(code);
ensureCapacity_unsynchronized(count + len);
Character.toChars(code, value, count);
count += len;
return this;
}
/**
* Append the <code>String</code> value of the argument to this * Append the <code>String</code> value of the argument to this
* <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert * <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert
* to <code>String</code>. * to <code>String</code>.
...@@ -497,21 +479,41 @@ public final class StringBuffer implements Serializable, CharSequence ...@@ -497,21 +479,41 @@ public final class StringBuffer implements Serializable, CharSequence
} }
/** /**
* Append the code point to this <code>StringBuffer</code>. * Append the <code>CharSequence</code> value of the argument to this
* This is like #append(char), but will append two characters * <code>StringBuffer</code>.
* if a supplementary code point is given.
* *
* @param code the code point to append * @param seq the <code>CharSequence</code> to append
* @return this <code>StringBuffer</code> * @return this <code>StringBuffer</code>
* @see Character#toChars(int, char[], int) * @see #append(Object)
* @since 1.5 * @since 1.5
*/ */
public synchronized StringBuffer appendCodePoint(int code) public synchronized StringBuffer append(CharSequence seq)
{ {
int len = Character.charCount(code); if (seq == null)
ensureCapacity_unsynchronized(count + len); seq = "null";
Character.toChars(code, value, count); return append(seq, 0, seq.length());
count += len; }
/**
* Append the specified subsequence of the <code>CharSequence</code>
* argument to this <code>StringBuffer</code>.
*
* @param seq the <code>CharSequence</code> to append
* @param start the starting index
* @param end one past the ending index
* @return this <code>StringBuffer</code>
* @see #append(Object)
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence seq, int start, int end)
{
if (seq == null)
seq = "null";
if (start < 0 || end < 0 || start > end || end > seq.length())
throw new IndexOutOfBoundsException();
ensureCapacity_unsynchronized(this.count + end - start);
for (int i = start; i < end; ++i)
value[count++] = seq.charAt(i);
return this; return this;
} }
......
...@@ -66,6 +66,10 @@ public: ...@@ -66,6 +66,10 @@ public:
private: private:
jboolean regionMatches(jint, ::java::lang::String *); jboolean regionMatches(jint, ::java::lang::String *);
public: public:
jint codePointAt(jint);
jint codePointBefore(jint);
jint codePointCount(jint, jint);
void trimToSize();
::java::lang::Appendable * append(::java::lang::CharSequence *, jint, jint); ::java::lang::Appendable * append(::java::lang::CharSequence *, jint, jint);
::java::lang::Appendable * append(::java::lang::CharSequence *); ::java::lang::Appendable * append(::java::lang::CharSequence *);
::java::lang::Appendable * append(jchar); ::java::lang::Appendable * append(jchar);
......
/* StringBuilder.java -- Unsynchronized growable strings /* StringBuilder.java -- Unsynchronized growable strings
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -998,4 +998,65 @@ public final class StringBuilder ...@@ -998,4 +998,65 @@ public final class StringBuilder
*/ */
// GCJ LOCAL: Native to access String internals properly. // GCJ LOCAL: Native to access String internals properly.
private native boolean regionMatches(int toffset, String other); private native boolean regionMatches(int toffset, String other);
/**
* 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 &gt;= length()
* @since 1.5
*/
public int codePointAt(int index)
{
return Character.codePointAt(value, index, count);
}
/**
* 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 &gt;= length()
* @since 1.5
*/
public int codePointBefore(int index)
{
// Character.codePointBefore() doesn't perform this check. We
// could use the CharSequence overload, but this is just as easy.
if (index >= count)
throw new IndexOutOfBoundsException();
return Character.codePointBefore(value, index, 1);
}
/**
* Returns the number of Unicode code points in the specified sub sequence.
* Surrogate pairs count as one code point.
* @param beginIndex the start of the subarray
* @param endIndex the index after the last char in the subarray
* @return the number of code points
* @throws IndexOutOfBoundsException if beginIndex is less than zero or
* greater than endIndex or if endIndex is greater than the length of this
* StringBuilder
*/
public int codePointCount(int beginIndex,int endIndex)
{
if (beginIndex < 0 || beginIndex > endIndex || endIndex > count)
throw new IndexOutOfBoundsException("invalid indices: " + beginIndex
+ ", " + endIndex);
return Character.codePointCount(value, beginIndex, endIndex - beginIndex);
}
public void trimToSize()
{
if (count < value.length)
{
char[] newValue = new char[count];
System.arraycopy(value, 0, newValue, 0, count);
value = newValue;
}
}
} }
...@@ -707,7 +707,7 @@ java::lang::String::regionMatches (jint toffset, ...@@ -707,7 +707,7 @@ java::lang::String::regionMatches (jint toffset,
} }
jint jint
java::lang::String::compareTo (jstring anotherString) java::lang::String::nativeCompareTo (jstring anotherString)
{ {
jchar *tptr = JvGetStringChars (this); jchar *tptr = JvGetStringChars (this);
jchar *optr = JvGetStringChars (anotherString); jchar *optr = JvGetStringChars (anotherString);
......
...@@ -751,7 +751,8 @@ _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz, ...@@ -751,7 +751,8 @@ _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
java::lang::StringBuffer *name_sig = java::lang::StringBuffer *name_sig =
new java::lang::StringBuffer (JvNewStringUTF (name)); new java::lang::StringBuffer (JvNewStringUTF (name));
name_sig->append ((jchar) ' ')->append (JvNewStringUTF (s)); name_sig->append ((jchar) ' ');
name_sig->append (JvNewStringUTF (s));
env->ex = new java::lang::NoSuchMethodError (name_sig->toString ()); env->ex = new java::lang::NoSuchMethodError (name_sig->toString ());
} }
catch (jthrowable t) catch (jthrowable t)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment