1 package gnu.expr; 2 import gnu.mapping.*; 3 import gnu.lists.Consumer; 4 5 8 9 public class Symbols 10 { 11 12 private Symbols () 13 { 14 } 15 16 private static int gensym_counter; 17 18 static synchronized int generateInt() 19 { 20 return ++gensym_counter; 21 } 22 23 52 53 57 public static final String gentemp () 58 { 59 return Symbols.make("GS." + Integer.toString(generateInt())); 60 } 61 62 67 static public String make (String name) 68 { 69 return name.intern(); 70 } 71 72 static public final String intern (String name) 73 { 74 return make (name); 75 } 76 77 public static void print(String name, Consumer out) 78 { 79 boolean readable = (out instanceof OutPort) 80 && ((OutPort)out).printReadable; 81 if (readable) 82 { 83 int len = name.length (); 84 for (int i = 0; i < len; i++) 85 { 86 char ch = name.charAt (i); 87 if (!(Character.isLowerCase (ch) 88 || ch == '!' || ch == '$' || ch == '%' || ch == '&' 89 || ch == '*' || ch == '/' || ch == ':' || ch == '<' 90 || ch == '=' || ch == '>' || ch == '?' || ch == '~' 91 || ch == '_' || ch == '^' 92 || ((ch == '+' || ch == '-') && (i > 0 || len == 1)) 93 || (Character.isDigit (ch) && i > 0) 94 || (ch == '.' && (i == 0 || name.charAt (i - 1) == '.')))) 95 out.write('\\'); 96 out.write(ch); 97 } 98 } 99 else 100 out.write(name); 101 } 102 103 } 104 | Popular Tags |