This is sort of the Java analogue of this question about C#.
Suppose I have a String object which I want to represent in code and I want to produce a st
String
My naive state machine implementation looks like this:
public String javaStringLiteral(String str) { StringBuilder sb = new StringBuilder("\""); for (int i=0; i= 0x80) { sb.append(String.format("\\u%04x", (int)c)); } else { sb.append(c); } } sb.append("\""); return sb.toString(); }