Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][engx] fix: use singleton in MetacharEscaper #273

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import com.google.common.escape.Escapers;

public class MetacharEscaper extends Escaper {
private static final MetacharEscaper SINGLETON = new MetacharEscaper();

// Handle escape characters (https://docs.oracle.com/javase/tutorial/java/data/characters.html)
// for the comments here, else JavaFormmater cannot properly format the string comment.
// `"` and `'` are overlooked because the comments will not be surrounded by `"` or `'`.
private static final Escaper escaper =
private static final Escaper charEscaper =
Escapers.builder()
.addEscape('\t', "\\t")
.addEscape('\b', "\\b")
Expand All @@ -35,10 +37,10 @@ private MetacharEscaper() {}

@Override
public String escape(String sourceString) {
return escaper.escape(sourceString);
return charEscaper.escape(sourceString);
}

public static String escaper(String source) {
return new MetacharEscaper().escape(source);
return SINGLETON.escape(source);
}
}