Fix Turtle syntax errors with multiline comments.

This commit is contained in:
Jim Balhoff 2023-02-15 09:58:25 -05:00
parent 97772ada1e
commit c3580528bb

View File

@ -472,7 +472,7 @@ public class Turtle {
writer.ln(); writer.ln();
if (!section.comments.isEmpty()) { if (!section.comments.isEmpty()) {
for (String s : section.comments) { for (String s : section.comments) {
writer.ln("# "+s); writer.ln("# "+formatMultilineComment(s));
} }
writer.ln(); writer.ln();
} }
@ -508,7 +508,7 @@ public class Turtle {
writer.write("]"); writer.write("]");
} }
} }
String comment = p.comment == null? "" : " # "+p.comment; String comment = p.comment == null? "" : " # "+formatMultilineComment(p.comment);
if (p.asList) writer.write(" )"); if (p.asList) writer.write(" )");
i++; i++;
if (i < sbj.predicates.size()) if (i < sbj.predicates.size())
@ -521,6 +521,11 @@ public class Turtle {
} }
} }
} }
private String formatMultilineComment(String s) {
return s.replace("\n", "\n#");
}
private void commitSection(StringBuilder b, Section section) throws Exception { private void commitSection(StringBuilder b, Section section) throws Exception {
b.append("# - "+section.name+" "+Utilities.padLeft("", '-', 75-section.name.length())+"\r\n"); b.append("# - "+section.name+" "+Utilities.padLeft("", '-', 75-section.name.length())+"\r\n");
@ -558,7 +563,7 @@ public class Turtle {
b.append("]"); b.append("]");
} }
} }
String comment = p.comment == null? "" : " # "+p.comment; String comment = p.comment == null? "" : " # "+formatMultilineComment(p.comment);
if (p.asList) b.append(" )"); if (p.asList) b.append(" )");
i++; i++;
if (i < sbj.predicates.size()) if (i < sbj.predicates.size())