1 package com4j.tlbimp; 2 3 import java.util.Collections ; 4 import java.util.HashSet ; 5 import java.util.Set ; 6 7 12 class Escape { 13 16 private static final Set reservedWords; 17 18 21 public static String escape( String identifier ) { 22 if(reservedWords.contains(identifier)) 23 return '_'+identifier; 24 else 25 return identifier; 26 } 27 28 static { 29 String [] words = new String [] { 31 "abstract", 32 "assert", 33 "boolean", 34 "break", 35 "byte", 36 "case", 37 "catch", 38 "char", 39 "class", 40 "const", 41 "continue", 42 "default", 43 "do", 44 "double", 45 "else", 46 "enum", 47 "extends", 48 "final", 49 "finally", 50 "float", 51 "for", 52 "goto", 53 "if", 54 "implements", 55 "import", 56 "instanceof", 57 "int", 58 "interface", 59 "long", 60 "native", 61 "new", 62 "package", 63 "private", 64 "protected", 65 "public", 66 "return", 67 "short", 68 "static", 69 "strictfp", 70 "super", 71 "switch", 72 "synchronized", 73 "this", 74 "throw", 75 "throws", 76 "transient", 77 "try", 78 "void", 79 "volatile", 80 "while" 81 }; 82 HashSet s = new HashSet (); 83 for( String w : words ) 84 s.add(w); 85 reservedWords = Collections.unmodifiableSet(s); 86 } 87 } 88 | Popular Tags |