1 12 package org.eclipse.jdt.internal.formatter.comment; 13 14 import java.io.IOException ; 15 import java.io.Reader ; 16 import java.util.HashMap ; 17 import java.util.Map ; 18 19 import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; 20 21 28 public class Java2HTMLEntityReader extends SubstitutionTextReader { 29 30 private static final int BEGIN_LINE = 0x01; 31 32 33 private static final Map fgEntityLookup; 34 35 static { 36 fgEntityLookup= new HashMap (7); 37 fgEntityLookup.put("<", "<"); fgEntityLookup.put(">", ">"); fgEntityLookup.put("&", "&"); fgEntityLookup.put("^", "ˆ"); fgEntityLookup.put("~", "˜"); fgEntityLookup.put("\"", """); } 44 45 private int bits = BEGIN_LINE; 46 47 52 public Java2HTMLEntityReader(Reader reader) { 53 super(reader); 54 setSkipWhitespace(false); 55 } 56 57 60 protected String computeSubstitution(int c) throws IOException { 61 StringBuffer buf = new StringBuffer (); 62 while (c == '*') { 64 this.bits &= ~BEGIN_LINE; 65 c = nextChar(); 66 buf.append('*'); 67 } 68 if (c == -1) 69 return buf.toString(); 71 if (c == '/' && buf.length() > 0) { 72 78 buf.setLength(buf.length() - 1); 79 buf.append("*/"); } else if (c == '@' && (this.bits & BEGIN_LINE) != 0) { 81 86 buf.append("@"); } else { 88 92 String entity = (String ) fgEntityLookup.get(String.valueOf((char) c)); 93 if (entity != null) 94 buf.append(entity); 95 else 96 buf.append((char) c); 97 } 98 if (c == '\n' || c == '\r') { 100 this.bits |= BEGIN_LINE; 101 } else if (!ScannerHelper.isWhitespace((char) c)) { 102 this.bits &= ~BEGIN_LINE; 103 } 104 return buf.toString(); 105 } 106 } 107 | Popular Tags |