Hi, the following patch makes javax.swing.Utilities.getNextWord 'pixel-perfect' with the behavior of the RI. There is a mauve test ensuring that.
The ChangeLog:
2006-04-28 Robert Schuster <[EMAIL PROTECTED]>
* javax/swing/text/Utilities.java:
(getNextWord): Use codePointAt instead of charAt, added note, changed
if-expression, added throwing of exception.
(getPreviousWord): Use codePointAt instead of charAt.
cya
Robert
Index: javax/swing/text/Utilities.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/Utilities.java,v
retrieving revision 1.31
diff -u -r1.31 Utilities.java
--- javax/swing/text/Utilities.java 27 Apr 2006 10:01:29 -0000 1.31
+++ javax/swing/text/Utilities.java 28 Apr 2006 09:40:47 -0000
@@ -48,6 +48,7 @@
* inside this package.
*
* @author Roman Kennke ([EMAIL PROTECTED])
+ * @author Robert Schuster ([EMAIL PROTECTED])
*/
public class Utilities
{
@@ -321,21 +322,31 @@
String text = c.getText();
BreakIterator wb = BreakIterator.getWordInstance();
wb.setText(text);
+
int last = wb.following(offs);
int current = wb.next();
+ int cp;
+
while (current != BreakIterator.DONE)
{
for (int i = last; i < current; i++)
{
- // FIXME: Should use isLetter(int) and text.codePointAt(int)
- // instead, but isLetter(int) isn't implemented yet
- if (Character.isLetter(text.charAt(i)))
+ cp = text.codePointAt(i);
+
+ // Return the last found bound if there is a letter at the current
+ // location or is not whitespace (meaning it is a number or
+ // punctuation). The first case means that 'last' denotes the
+ // beginning of a word while the second case means it is the start
+ // of some else.
+ if (Character.isLetter(cp)
+ || !Character.isWhitespace(cp))
return last;
}
last = current;
current = wb.next();
}
- return BreakIterator.DONE;
+
+ throw new BadLocationException("no more word", offs);
}
/**
@@ -364,9 +375,7 @@
{
for (int i = last; i < offs; i++)
{
- // FIXME: Should use isLetter(int) and text.codePointAt(int)
- // instead, but isLetter(int) isn't implemented yet
- if (Character.isLetter(text.charAt(i)))
+ if (Character.isLetter(text.codePointAt(i)))
return last;
}
last = current;
signature.asc
Description: OpenPGP digital signature
