From c3580528bb71447ff7047bb9dd0aba71fb440ab5 Mon Sep 17 00:00:00 2001 From: Jim Balhoff Date: Wed, 15 Feb 2023 09:58:25 -0500 Subject: [PATCH] Fix Turtle syntax errors with multiline comments. --- .../java/org/hl7/fhir/utilities/turtle/Turtle.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/turtle/Turtle.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/turtle/Turtle.java index e30d36d38..59fd5e916 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/turtle/Turtle.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/turtle/Turtle.java @@ -472,7 +472,7 @@ public class Turtle { writer.ln(); if (!section.comments.isEmpty()) { for (String s : section.comments) { - writer.ln("# "+s); + writer.ln("# "+formatMultilineComment(s)); } writer.ln(); } @@ -508,7 +508,7 @@ public class Turtle { writer.write("]"); } } - String comment = p.comment == null? "" : " # "+p.comment; + String comment = p.comment == null? "" : " # "+formatMultilineComment(p.comment); if (p.asList) writer.write(" )"); i++; 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 { b.append("# - "+section.name+" "+Utilities.padLeft("", '-', 75-section.name.length())+"\r\n"); @@ -558,7 +563,7 @@ public class Turtle { b.append("]"); } } - String comment = p.comment == null? "" : " # "+p.comment; + String comment = p.comment == null? "" : " # "+formatMultilineComment(p.comment); if (p.asList) b.append(" )"); i++; if (i < sbj.predicates.size())