How to unescape a Java string literal in Java?
I'm processing some Java source code using Java. I'm extracting the string literals and feeding them to a function taking a String. The problem is that I need to pass the unescaped version of the String to the function (ie. this means converting n
to a newline, and to a single
, etc).
Is there a function inside the Java API that does this? If not, can I obtain such functionality from some library? Obviously the Java compiler has to do this conversion.
PS - In case anyone wants to know: I'm trying to unobfuscate string literals in decompiled obfuscated Java files
EDIT: You can download the full source for the function I discuss below. I also discuss it in more detail in this answer.
The Problem
The org.apache.commons.lang.StringEscapeUtils.unescapeJava()
given here as “the answer” is really very little help at all.