1 package persistence.antlr; 2 3 8 9 13 class CSharpCharFormatter implements CharFormatter { 14 15 16 24 public String escapeChar(int c, boolean forCharLiteral) { 25 switch (c) 26 { 27 case '\n' : return "\\n"; 29 case '\t' : return "\\t"; 30 case '\r' : return "\\r"; 31 case '\\' : return "\\\\"; 32 case '\'' : return forCharLiteral ? "\\'" : "'"; 33 case '"' : return forCharLiteral ? "\"" : "\\\""; 34 default : 35 if ( c<' '||c>126 ) 36 { 37 if ( ( 0x0000 <= c ) && ( c <= 0x000F ) ) 38 { 39 return "\\u000" + Integer.toString(c,16); 40 } 41 else if ( ( 0x0010 <= c ) && ( c <= 0x00FF ) ) 42 { 43 return "\\u00" + Integer.toString(c,16); 44 } 45 else if ( ( 0x0100 <= c ) && ( c <= 0x0FFF )) 46 { 47 return "\\u0" + Integer.toString(c,16); 48 } 49 else 50 { 51 return "\\u" + Integer.toString(c,16); 52 } 53 } 54 else 55 { 56 return String.valueOf((char)c); 57 } 58 } 59 } 60 61 62 66 public String escapeString(String s) 67 { 68 String retval = new String (); 69 for (int i = 0; i < s.length(); i++) 70 { 71 retval += escapeChar(s.charAt(i), false); 72 } 73 return retval; 74 } 75 76 77 83 public String literalChar(int c) 84 { 85 return "'" + escapeChar(c, true) + "'"; 86 } 87 88 89 94 public String literalString(String s) 95 { 96 return "@\"\"\"" + escapeString(s) + "\"\"\""; 98 } 99 } 100 | Popular Tags |