Commit 37d41553 by Tom Tromey Committed by Tom Tromey

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
parent 2b15cf3b
2006-01-06 Tom Tromey <tromey@redhat.com>
* 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.
2005-12-26 Anthony Green <green@redhat.com>
* gnu/java/nio/SocketChannelImpl.java (read): Compute the right amount
......
/* String.java -- immutable character sequences; the object of string literals
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -455,6 +455,40 @@ public final class String implements Serializable, Comparable, CharSequence
public native char charAt(int index);
/**
* 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 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 &gt;= 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);
}
/**
* 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.
......@@ -566,6 +600,18 @@ public final class String implements Serializable, Comparable, CharSequence
public native boolean contentEquals(StringBuffer buffer);
/**
* 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);
/**
* 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>
......@@ -1259,6 +1305,88 @@ public final class String implements Serializable, Comparable, CharSequence
*/
public native String intern();
/**
* 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)
{
if (start < 0 || end >= count || start > end)
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();
}
private native void init(char[] chars, int offset, int count,
boolean dont_copy);
......
// natString.cc - Implementation of java.lang.String native methods.
/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation
/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of libgcj.
......@@ -15,6 +15,7 @@ details. */
#include <gcj/cni.h>
#include <java/lang/Character.h>
#include <java/lang/CharSequence.h>
#include <java/lang/String.h>
#include <java/lang/IndexOutOfBoundsException.h>
#include <java/lang/ArrayIndexOutOfBoundsException.h>
......@@ -564,6 +565,18 @@ java::lang::String::contentEquals(java::lang::StringBuffer* buffer)
return true;
}
jboolean
java::lang::String::contentEquals(java::lang::CharSequence *seq)
{
if (seq->length() != count)
return false;
jchar *value = JvGetStringChars(this);
for (int i = 0; i < count; ++i)
if (value[i] != seq->charAt(i))
return false;
return true;
}
jchar
java::lang::String::charAt(jint i)
{
......
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