1 9 10 package org.jboss.portal.format.parser.linebreak; 11 12 import org.jboss.portal.format.parser.AbstractParser; 13 import org.jboss.portal.format.parser.ParseEvent; 14 import org.jboss.portal.format.parser.TextEvent; 15 16 22 public class LineBreakParser extends AbstractParser 23 { 24 25 private static final LineBreakEvent event = new LineBreakEvent(); 26 27 private final TextEvent textEvent = new TextEvent(); 28 29 public void parse(char[] chars, int startOffset, int length) 30 { 31 int endOffset = startOffset + length; 32 int previousOffset = startOffset; 33 for (int currentOffset = startOffset;currentOffset < endOffset;currentOffset++) 34 { 35 char c = chars[currentOffset]; 36 if (c == '\n') 37 { 38 if (currentOffset > previousOffset) 39 { 40 textEvent.setText(chars, previousOffset, currentOffset - previousOffset); 41 handler.handle(textEvent); 42 } 43 handler.handle(event); 44 previousOffset = currentOffset + 1; 45 } 46 } 47 if (endOffset > previousOffset) 48 { 49 textEvent.setText(chars, previousOffset, endOffset - previousOffset); 50 handler.handle(textEvent); 51 } 52 } 53 54 public static class LineBreakEvent implements ParseEvent 55 { 56 } 57 } 58 | Popular Tags |