1 19 20 package edu.umd.cs.findbugs.xml; 21 22 import java.io.IOException ; 23 24 import edu.umd.cs.findbugs.annotations.NonNull; 25 26 32 public abstract class QuoteMetaCharacters { 33 private String text; 34 private MetaCharacterMap map; 35 36 42 public QuoteMetaCharacters(@NonNull String text, @NonNull MetaCharacterMap map) { 43 if (text == null) throw new NullPointerException ("text must be nonnull"); 44 if (map == null) throw new NullPointerException ("map must be nonnull"); 45 this.text = text; 46 this.map = map; 47 } 48 49 52 public void process() throws IOException { 53 int pos = 0; 54 do { 55 int meta = findNextMeta(text, pos); 56 if (meta >= 0) { 57 emitLiteral(text.substring(pos, meta)); 58 emitLiteral(map.getReplacement(text.substring(meta, meta + 1))); 59 pos = meta + 1; 60 } else { 61 emitLiteral(text.substring(pos, text.length())); 62 pos = text.length(); 63 } 64 } while (pos < text.length()); 65 } 66 67 74 public abstract void emitLiteral(String s) throws IOException ; 75 76 private int findNextMeta(String s, int start) { 77 for (int i = start; i < s.length(); ++i) { 78 char c = s.charAt(i); 79 if (map.isMeta(c)) 80 return i; 81 } 82 return -1; 83 } 84 } 85 86 | Popular Tags |