diff options
author | Mark Wielaard <mark@klomp.org> | 2007-03-05 17:27:44 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-03-05 17:27:44 +0000 |
commit | 666ff4f65d256dec0974941605cf76db0b138a76 (patch) | |
tree | 7094a7844e13e49f92832894c3b7a7f8ff638d8b /libjava/java/lang/StringBuilder.java | |
parent | b48a45922ddcdfd0aa2cd3ff24c7c158d20c1f2e (diff) | |
download | gcc-666ff4f65d256dec0974941605cf76db0b138a76.zip gcc-666ff4f65d256dec0974941605cf76db0b138a76.tar.gz gcc-666ff4f65d256dec0974941605cf76db0b138a76.tar.bz2 |
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
Diffstat (limited to 'libjava/java/lang/StringBuilder.java')
-rw-r--r-- | libjava/java/lang/StringBuilder.java | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/libjava/java/lang/StringBuilder.java b/libjava/java/lang/StringBuilder.java index 5f33b2e..55a49e6 100644 --- a/libjava/java/lang/StringBuilder.java +++ b/libjava/java/lang/StringBuilder.java @@ -1,5 +1,5 @@ /* 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. This file is part of GNU Classpath. @@ -998,4 +998,65 @@ public final class StringBuilder */ // GCJ LOCAL: Native to access String internals properly. 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 >= 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 >= 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; + } + } } |