LispWriter { public void writeChar(char c) { output.write("?"); switch (c) { case '\"': case '\'': case '\\': case '?': case ')': case '(': case ']': case '[': output.write("\\"); output.write(c); break; case '\n': output.write("\\n"); break; case '\b': output.write("\\b"); break; case '\r': output.write("\\r"); break; case '\t': output.write("\\t"); break; case '\f': output.write("\\f"); break; default: output.write(c); break; } } LispWriter(PrintWriter dest); boolean isAutoQuoteLists(); void setAutoQuoteLists(boolean autoQuoteLists); void writeList(List<Cons> list); void writeForm(List<Cons> list); void writeAlist(Map<Object, Object> map); void writeCons(Cons cons); void writeString(String string); void writeInt(int n); void writeInt(Integer n); void writeLong(long n); void writeLong(Long n); void writeFloat(float f); void writeFloat(Float f); void writeDouble(double d); void writeDouble(Double d); void writeChar(char c); void writeChar(Character c); void writeBoolean(boolean b); void writeBoolean(Boolean b); void writeT(); void writeNil(); void writeSymbol(Symbol name); void writeQuoted(Quoted q); void writeUnknown(Object o); static final Symbol T; static final Symbol NIL; static final Quoted NULL; }
@Test public void testChars() { lwriter.writeChar('a'); assertEquals("?a", output.toString()); reset(); lwriter.writeChar('?'); assertEquals("?\\?", output.toString()); reset(); lwriter.writeChar('\\'); assertEquals("?\\\\", output.toString()); }