Skip to content

Commit

Permalink
Fix comment writing (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: liach <liach@users.noreply.github.com>
  • Loading branch information
liach authored and modmuss50 committed Dec 5, 2019
1 parent db32fe3 commit 00c5b1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = stitch
description = Fabric auxillary Tiny tools
url = https://github.com/FabricMC/stitch
version = 0.4.0
version = 0.4.1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

public class TinyMethod implements Comparable<TinyMethod>, Mapping {

@Override
public String toString() {
return "TinyMethod(names = [" + String.join(", ", methodNames) + "], desc = " + methodDescriptorInFirstNamespace
+ ", " + parameters.size() + " params, "
+ localVariables.size() + " vars, " + comments.size() + " comments)";
}

/**
* For example when we have official -> named mappings the descriptor will be in official, but in named -> official
* the descriptor will be in named.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,26 @@ private void writeField(TinyField field) {


private void writeComment(int indentLevel, String comment) {
writeLine(indentLevel, Prefixes.COMMENT, comment);
writeLine(indentLevel, Prefixes.COMMENT, escapeComment(comment));
}

private static String escapeComment(String old) {
StringBuilder sb = new StringBuilder(old.length());
for (int i = 0; i < old.length(); i++) {
char c = old.charAt(i);
int t = TO_ESCAPE.indexOf(c);
if (t == -1) {
sb.append(c);
} else {
sb.append('\\').append(ESCAPED.charAt(t));
}
}
return sb.toString();
}

private static final String TO_ESCAPE = "\\\n\r\0\t";
private static final String ESCAPED = "\\nr0t";


private void write(int indentLevel, String... tabSeparatedStrings) {
try {
Expand Down

0 comments on commit 00c5b1a

Please sign in to comment.