1 16 package com.google.gwt.core.ext; 17 18 22 public abstract class Generator { 23 24 30 public static String escape(String unescaped) { 31 int extra = 0; 32 for (int in = 0, n = unescaped.length(); in < n; ++in) { 33 switch (unescaped.charAt(in)) { 34 case '\n': 35 case '\r': 36 case '\"': 37 case '\\': 38 ++extra; 39 break; 40 } 41 } 42 43 if (extra == 0) { 44 return unescaped; 45 } 46 47 char[] oldChars = unescaped.toCharArray(); 48 char[] newChars = new char[oldChars.length + extra]; 49 for (int in = 0, out = 0, n = oldChars.length; in < n; ++in, ++out) { 50 char c = oldChars[in]; 51 switch (c) { 52 case '\n': 53 newChars[out++] = '\\'; 54 c = 'n'; 55 break; 56 case '\r': 57 newChars[out++] = '\\'; 58 c = 'r'; 59 break; 60 case '\"': 61 newChars[out++] = '\\'; 62 c = '"'; 63 break; 64 case '\\': 65 newChars[out++] = '\\'; 66 c = '\\'; 67 break; 68 } 69 newChars[out] = c; 70 } 71 72 return String.valueOf(newChars); 73 } 74 75 85 public abstract String generate(TreeLogger logger, GeneratorContext context, 86 String typeName) throws UnableToCompleteException; 87 } 88 | Popular Tags |