diff options
Diffstat (limited to 'libjava/classpath/gnu/javax/swing/text/html/parser/support/textPreProcessor.java')
-rw-r--r-- | libjava/classpath/gnu/javax/swing/text/html/parser/support/textPreProcessor.java | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/support/textPreProcessor.java b/libjava/classpath/gnu/javax/swing/text/html/parser/support/textPreProcessor.java index cc1610585a6..6fd79e2589e 100644 --- a/libjava/classpath/gnu/javax/swing/text/html/parser/support/textPreProcessor.java +++ b/libjava/classpath/gnu/javax/swing/text/html/parser/support/textPreProcessor.java @@ -42,17 +42,17 @@ import gnu.javax.swing.text.html.parser.support.low.Constants; /** * Pre - processes text in text parts of the html document. - * Not thread - safe. + * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class textPreProcessor { /** - * Pre - process non-preformatted text. - * \t, \r and \n mutate into spaces, then multiple spaces mutate - * into single one, all whitespace around tags is consumed. - * The content of the passed buffer is destroyed. - * @param text A text to pre-process. + * Pre - process non-preformatted text. \t, \r and \n mutate into spaces, then + * multiple spaces mutate into single one, all whitespace around tags is + * consumed. The content of the passed buffer is destroyed. + * + * @param a_text A text to pre-process. */ public char[] preprocess(StringBuffer a_text) { @@ -64,18 +64,15 @@ public class textPreProcessor int a = 0; int b = text.length - 1; - try - { - while (Constants.bWHITESPACE.get(text [ a ])) - a++; - while (Constants.bWHITESPACE.get(text [ b ])) - b--; - } - catch (ArrayIndexOutOfBoundsException sx) - { - // A text fragment, consisting from line breaks only. - return null; - } + // Remove leading/trailing whitespace, leaving at most one character + int len = text.length; + while (a + 1 < len && Constants.bWHITESPACE.get(text[a]) + && Constants.bWHITESPACE.get(text[a + 1])) + a++; + + while (b > a && Constants.bWHITESPACE.get(text[b]) + && Constants.bWHITESPACE.get(text[b - 1])) + b--; a_text.setLength(0); @@ -83,10 +80,9 @@ public class textPreProcessor boolean spaceNow; char c; - chars: - for (int i = a; i <= b; i++) + chars: for (int i = a; i <= b; i++) { - c = text [ i ]; + c = text[i]; spaceNow = Constants.bWHITESPACE.get(c); if (spacesWere && spaceNow) continue chars; |