Skip to content

Commit

Permalink
[ggj][engx] fix: use singleton in MetacharEscaper (#273)
Browse files Browse the repository at this point in the history
* fix: use singleton in MetacharEscaper

* fix: merge
  • Loading branch information
miraleung authored Sep 4, 2020
1 parent 155aeb2 commit b78dbc9
Showing 1 changed file with 5 additions and 3 deletions.
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);
}
}

0 comments on commit b78dbc9

Please sign in to comment.