
org.inferred.freebuilder.processor.source.Quotes Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of freebuilder Show documentation
Show all versions of freebuilder Show documentation
Automatic generation of the Builder pattern for Java 1.6+
The newest version!
package org.inferred.freebuilder.processor.source;
public class Quotes {
/** Escapes each character in a string that has an escape sequence. */
public static CharSequence escapeJava(CharSequence s) {
return quote(s, 0, s.length());
}
public static CharSequence quote(CharSequence s, int start, int end) {
StringBuilder buf = new StringBuilder();
for (int i = start; i < end; i++) {
appendQuoted(buf, s.charAt(i));
}
return buf;
}
private static void appendQuoted(StringBuilder buf, char ch) {
switch (ch) {
case '\b':
buf.append("\\b");
return;
case '\f':
buf.append("\\f");
return;
case '\n':
buf.append("\\n");
return;
case '\r':
buf.append("\\r");
return;
case '\t':
buf.append("\\t");
return;
case '\"':
buf.append("\\\"");
return;
case '\\':
buf.append("\\\\");
return;
default:
buf.append(ch);
return;
}
}
private Quotes() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy