You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/12/22 18:34:47 UTC

[1/4] jena git commit: JENA-1098: Pass Context to writer operations (Turtle and Trig).

Repository: jena
Updated Branches:
  refs/heads/master 8e615f162 -> 95d1ac85c


JENA-1098: Pass Context to writer operations (Turtle and Trig).

Use the system-wide Context by default.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/95d1ac85
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/95d1ac85
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/95d1ac85

Branch: refs/heads/master
Commit: 95d1ac85cc04b32c31ab6cd71f4f0309c1f81067
Parents: 8feb15e
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Dec 21 13:19:35 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Dec 22 17:32:00 2015 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/jena/riot/RDFDataMgr.java   |  8 ++++----
 .../src/main/java/org/apache/jena/riot/RIOT.java     | 10 ++++++++++
 .../jena/riot/out/NodeFormatterTTL_MultiLine.java    |  1 +
 .../java/org/apache/jena/riot/writer/TriGWriter.java |  9 +++++----
 .../org/apache/jena/riot/writer/TriGWriterBase.java  | 10 +++++-----
 .../apache/jena/riot/writer/TriGWriterBlocks.java    |  3 ++-
 .../org/apache/jena/riot/writer/TriGWriterFlat.java  |  3 ++-
 .../org/apache/jena/riot/writer/TurtleShell.java     | 15 +++++++--------
 .../org/apache/jena/riot/writer/TurtleWriter.java    | 10 ++++++----
 .../apache/jena/riot/writer/TurtleWriterBase.java    | 10 +++++-----
 .../apache/jena/riot/writer/TurtleWriterBlocks.java  |  3 ++-
 .../apache/jena/riot/writer/TurtleWriterFlat.java    |  3 ++-
 12 files changed, 51 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java b/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
index ba8e398..e20b2b0 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
@@ -1209,22 +1209,22 @@ public class RDFDataMgr
 
     private static void write$(OutputStream out, Graph graph, RDFFormat serialization) {
         WriterGraphRIOT w = createGraphWriter$(serialization);
-        w.write(out, graph, RiotLib.prefixMap(graph), null, (Context)null);
+        w.write(out, graph, RiotLib.prefixMap(graph), null, RIOT.getContext());
     }
 
     private static void write$(Writer out, Graph graph, RDFFormat serialization) {
         WriterGraphRIOT w = createGraphWriter$(serialization);
-        w.write(out, graph, RiotLib.prefixMap(graph), null, (Context)null);
+        w.write(out, graph, RiotLib.prefixMap(graph), null, RIOT.getContext());
     }
 
     private static void write$(OutputStream out, DatasetGraph dataset, RDFFormat serialization) {
         WriterDatasetRIOT w = createDatasetWriter$(serialization);
-        w.write(out, dataset, RiotLib.prefixMap(dataset), null, (Context)null);
+        w.write(out, dataset, RiotLib.prefixMap(dataset), null, RIOT.getContext());
     }
 
     private static void write$(Writer out, DatasetGraph dataset, RDFFormat serialization) {
         WriterDatasetRIOT w = createDatasetWriter$(serialization);
-        w.write(out, dataset, RiotLib.prefixMap(dataset), null, (Context)null);
+        w.write(out, dataset, RiotLib.prefixMap(dataset), null, RIOT.getContext());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
index d0e80e9..16c63d7 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
@@ -21,6 +21,8 @@ package org.apache.jena.riot ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.mgt.SystemInfo ;
+import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.sparql.util.Symbol ;
 import org.apache.jena.system.JenaSystem ;
 
 public class RIOT {
@@ -45,6 +47,14 @@ public class RIOT {
 
     /** The root package name for RIOT */
     public static final String PATH    = "org.apache.jena.riot" ;
+    
+    /** Control of multiline literals */ 
+    public static final Symbol multilineLiterals = Symbol.create("riot.multiline_literals") ;
+    
+    /** The system-wide context */
+    public static Context getContext() {
+        return ARQ.getContext();
+    }
 
     public static void init() {
         if ( initialized )

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
index 5ee826c..bd843a8 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
@@ -104,6 +104,7 @@ public class NodeFormatterTTL_MultiLine extends NodeFormatterTTL {
         IndentedWriter iw = null ;
         if ( writer instanceof IndentedWriter ) {
             iw = (IndentedWriter)writer ;
+            iw.pad(); 
             indent = iw.getAbsoluteIndent() ;
             iw.setAbsoluteIndent(0);
         }

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
index 6bde73f..b0d5afc 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriter.java
@@ -32,20 +32,21 @@ import org.apache.jena.graph.Node ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.util.Context ;
 
 /** TriG pretty writer */
 public class TriGWriter extends TriGWriterBase
 {
     @Override
-    protected void output(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI) {
-        TriGWriter$ w = new TriGWriter$(iOut, prefixMap, baseURI) ;
+    protected void output(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI, Context context) {
+        TriGWriter$ w = new TriGWriter$(iOut, prefixMap, baseURI, context) ;
         w.write(dsg) ;
     }
 
     private static class TriGWriter$ extends TurtleShell
     {
-        TriGWriter$(IndentedWriter out, PrefixMap prefixMap, String baseURI) {
-            super(out, prefixMap, baseURI) ;
+        TriGWriter$(IndentedWriter out, PrefixMap prefixMap, String baseURI, Context context) {
+            super(out, prefixMap, baseURI, context) ;
         }
 
         private void write(DatasetGraph dsg) {

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBase.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBase.java
index 9d3b080..6c591a5 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBase.java
@@ -40,21 +40,21 @@ public abstract class TriGWriterBase extends WriterDatasetRIOTBase
     @Override
     public void write(Writer out, DatasetGraph dsg, PrefixMap prefixMap, String baseURI, Context context) {
         IndentedWriter iOut = RiotLib.create(out) ;
-        output$(iOut, dsg, prefixMap, baseURI) ;
+        output$(iOut, dsg, prefixMap, baseURI, context) ;
     }
 
     @Override
     public void write(OutputStream out, DatasetGraph dsg, PrefixMap prefixMap, String baseURI, Context context) {
         IndentedWriter iOut = new IndentedWriter(out) ;
-        output$(iOut, dsg, prefixMap, baseURI) ;
+        output$(iOut, dsg, prefixMap, baseURI, context) ;
     }
 
-    private void output$(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI) {
+    private void output$(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI, Context context) {
         if ( baseURI != null )
             baseURI = IRIResolver.resolveString(baseURI) ;
-        output(iOut, dsg, prefixMap, baseURI) ;
+        output(iOut, dsg, prefixMap, baseURI, context) ;
         iOut.flush() ;
     }
 
-    protected abstract void output(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI) ;
+    protected abstract void output(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI, Context context) ;
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBlocks.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBlocks.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBlocks.java
index f8ab142..2161d32 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBlocks.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterBlocks.java
@@ -23,6 +23,7 @@ import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.util.Context ;
 
 /** TriG writer that streams - print in blocks of quads clustered
  *  by adjacent same graph and same subject
@@ -30,7 +31,7 @@ import org.apache.jena.sparql.core.DatasetGraph ;
 public class TriGWriterBlocks extends TriGWriterBase
 {
     @Override
-    protected void output(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI) {
+    protected void output(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI, Context context) {
         StreamRDF dest = new WriterStreamRDFBlocks(iOut) ;
         dest.start() ;
         dest.base(baseURI) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterFlat.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterFlat.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterFlat.java
index af9648e..46025b7 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterFlat.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TriGWriterFlat.java
@@ -23,6 +23,7 @@ import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.util.Context ;
 
 /** TriG writer that writes quads one per line
  *  in TriG form with prefixes and short form literals (e.g. integers) 
@@ -31,7 +32,7 @@ import org.apache.jena.sparql.core.DatasetGraph ;
 public class TriGWriterFlat extends TriGWriterBase
 {
     @Override
-    protected void output(IndentedWriter iOut, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI) {
+    protected void output(IndentedWriter iOut, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI, Context context) {
         StreamRDF dest = new WriterStreamRDFFlat(iOut) ;
         dest.start() ;
         dest.base(baseURI) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
index bfc10ff..041386f 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
@@ -43,6 +43,7 @@ import org.apache.jena.atlas.lib.SetUtils ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
+import org.apache.jena.riot.RIOT ;
 import org.apache.jena.riot.other.GLib ;
 import org.apache.jena.riot.out.NodeFormatter ;
 import org.apache.jena.riot.out.NodeFormatterTTL ;
@@ -53,6 +54,7 @@ import org.apache.jena.riot.system.PrefixMapFactory ;
 import org.apache.jena.riot.system.RiotLib ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.util.iterator.ExtendedIterator ;
 import org.apache.jena.vocabulary.RDF ;
 import org.apache.jena.vocabulary.RDFS ;
@@ -61,24 +63,21 @@ import org.apache.jena.vocabulary.RDFS ;
  * Base class to support the pretty forms of Turtle-related languages (Turtle, TriG)
  */
 public abstract class TurtleShell {
-    public static boolean enableMultiLine = false ; 
-    
     protected final IndentedWriter out ;
     protected final NodeFormatter  nodeFmt ;
     protected final PrefixMap      prefixMap ;
     protected final String         baseURI ;
 
-    protected TurtleShell(IndentedWriter out, PrefixMap pmap, String baseURI) {
+    protected TurtleShell(IndentedWriter out, PrefixMap pmap, String baseURI, Context context) {
         this.out = out ;
         if ( pmap == null )
             pmap = PrefixMapFactory.emptyPrefixMap() ;
-        if ( ! enableMultiLine )
-            this.nodeFmt = new NodeFormatterTTL(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;
-        else
-            // JENA-1098 - Work-in-progress.
-            this.nodeFmt = new NodeFormatterTTL_MultiLine(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;
         this.prefixMap = pmap ;
         this.baseURI = baseURI ;
+        if ( context != null && context.isTrue(RIOT.multilineLiterals) )
+            this.nodeFmt = new NodeFormatterTTL_MultiLine(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;    
+        else
+            this.nodeFmt = new NodeFormatterTTL(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;
     }
 
     protected void writeBase(String base) {

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriter.java
index 96b5b26..686c1ba 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriter.java
@@ -21,17 +21,19 @@ package org.apache.jena.riot.writer ;
 import org.apache.jena.atlas.io.IndentedWriter ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.riot.system.PrefixMap ;
+import org.apache.jena.sparql.util.Context ;
 
 public class TurtleWriter extends TurtleWriterBase {
+    
     @Override
-    protected void output(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI) {
-        TurtleWriter$ w = new TurtleWriter$(iOut, prefixMap, baseURI) ;
+    protected void output(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
+        TurtleWriter$ w = new TurtleWriter$(iOut, prefixMap, baseURI, context) ;
         w.write(graph) ;
     }
 
     private static class TurtleWriter$ extends TurtleShell {
-        public TurtleWriter$(IndentedWriter out, PrefixMap prefixMap, String baseURI) {
-            super(out, prefixMap, baseURI) ;
+        public TurtleWriter$(IndentedWriter out, PrefixMap prefixMap, String baseURI, Context context) {
+            super(out, prefixMap, baseURI, context) ;
         }
 
         private void write(Graph graph) {

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBase.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBase.java
index 722da48..625d92d 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBase.java
@@ -39,21 +39,21 @@ public abstract class TurtleWriterBase extends WriterGraphRIOTBase
     @Override
     public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
         IndentedWriter iOut = RiotLib.create(out) ;
-        output$(iOut, graph, prefixMap, baseURI) ;
+        output$(iOut, graph, prefixMap, baseURI, context) ;
     }
 
     @Override
     public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
         IndentedWriter iOut = new IndentedWriter(out) ;
-        output$(iOut, graph, prefixMap, baseURI) ;
+        output$(iOut, graph, prefixMap, baseURI, context) ;
     }
 
-    private void output$(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI) {
+    private void output$(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
         if ( baseURI != null )
             baseURI = IRIResolver.resolveString(baseURI) ;
-        output(iOut, graph, prefixMap, baseURI) ;
+        output(iOut, graph, prefixMap, baseURI, context) ;
         iOut.flush() ;
     }
 
-    protected abstract void output(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI) ;
+    protected abstract void output(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI, Context context) ;
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBlocks.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBlocks.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBlocks.java
index 5551641..66bbf32 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBlocks.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterBlocks.java
@@ -23,6 +23,7 @@ import org.apache.jena.graph.Graph ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.sparql.util.Context ;
 
 /** Turtle writer that streams - print in blocks of triples formatted
  *  by adjacent same subject.
@@ -30,7 +31,7 @@ import org.apache.jena.riot.system.StreamRDF ;
 public class TurtleWriterBlocks extends TurtleWriterBase
 {
     @Override
-    protected void output(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI) {
+    protected void output(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
         StreamRDF dest = new WriterStreamRDFBlocks(out) ;
         dest.start() ;
         dest.base(baseURI) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/95d1ac85/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterFlat.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterFlat.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterFlat.java
index 0ea6c9f..4294a7d 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterFlat.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleWriterFlat.java
@@ -23,12 +23,13 @@ import org.apache.jena.graph.Graph ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.sparql.util.Context ;
 
 /** Write Turtle with omne triple on one line with prefixed names, with short form literals (e.g. integers) */   
 public class TurtleWriterFlat extends TurtleWriterBase
 {
     @Override
-    protected void output(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI) {
+    protected void output(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
         StreamRDF dest = new WriterStreamRDFFlat(out) ;
         dest.start() ;
         dest.base(baseURI) ;


[3/4] jena git commit: JENA-1098: Code multiline literals (not enabled in this commit)

Posted by an...@apache.org.
JENA-1098: Code multiline literals (not enabled in this commit)


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8feb15e6
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8feb15e6
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8feb15e6

Branch: refs/heads/master
Commit: 8feb15e6afd6aaeb7d80c44af35ed3de1e469346
Parents: 72bcb91
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Dec 20 17:36:19 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Dec 22 17:32:00 2015 +0000

----------------------------------------------------------------------
 .../riot/out/NodeFormatterTTL_MultiLine.java    | 117 +++++++++++++++++++
 .../apache/jena/riot/writer/TurtleShell.java    |  28 ++++-
 2 files changed, 140 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/8feb15e6/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
new file mode 100644
index 0000000..5ee826c
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL_MultiLine.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out;
+
+import static org.apache.jena.atlas.lib.Chars.CH_QUOTE1 ;
+import static org.apache.jena.atlas.lib.Chars.CH_QUOTE2 ;
+
+import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.riot.out.NodeFormatter ;
+import org.apache.jena.riot.out.NodeFormatterTTL ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutput ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutputTTL_MultiLine ;
+import org.apache.jena.riot.system.PrefixMap ;
+
+/** 
+ * Node formatter for pretty-printed Turtle.
+ *  This {@link NodeFormatter} switches between " and ' quotes to avoid ecapes.
+ *  This code writes multiline literals with """ or '''. 
+ */
+public class NodeFormatterTTL_MultiLine extends NodeFormatterTTL {
+    /// For '-quoted and "-quoted literals 
+    private final QuotedStringOutput escapeProc2 = new QuotedStringOutputTTL_MultiLine(CH_QUOTE2) ;
+    private final QuotedStringOutput escapeProc1 = new QuotedStringOutputTTL_MultiLine(CH_QUOTE1) ;
+
+    private boolean writeAsMultiLine(AWriter w, String lex) {
+        return ( lex.contains("\n") ) ;
+    }
+
+    public NodeFormatterTTL_MultiLine(String baseIRI, PrefixMap prefixMap) {
+        super(baseIRI, prefixMap) ;
+    }
+
+    public NodeFormatterTTL_MultiLine(String baseIRI, PrefixMap prefixMap, NodeToLabel nodeToLabel) {
+        super(baseIRI, prefixMap, nodeToLabel);
+    }
+
+    private Runnable noop = ()->{} ;
+
+    @Override
+    public void formatLitString(AWriter w, String lex)
+    {
+        if ( ! writeAsMultiLine(w, lex) ) {
+            writeLexicalSingleLine(w, lex, noop);
+            return ;
+        }
+        writeLexicalMultiLine(w, lex, noop) ; 
+    }
+
+    // To do ....
+    @Override
+    public void formatLitLang(AWriter w, String lex, String langTag) {
+        if ( ! writeAsMultiLine(w, lex) ) {
+            super.formatLitLang(w, lex, langTag);
+            return ;
+        }
+        writeLexicalMultiLine(w, lex, ()->{ w.print('@') ; w.print(langTag) ; }) ;
+    }
+
+    @Override
+    protected void writeLiteralLongForm(AWriter w, String lex, String datatypeURI)
+    {
+        if ( ! writeAsMultiLine(w, lex) ) {
+            super.writeLiteralOneLine(w, lex, datatypeURI);
+            return ;
+        }
+        writeLexicalMultiLine(w, lex, ()-> { w.print("^^") ; formatURI(w, datatypeURI) ; }) ;
+    }
+
+    private QuotedStringOutput chooseEscapeProcessor(String str) {
+        QuotedStringOutput proc = escapeProc2 ;
+        if ( str.indexOf(CH_QUOTE2) >= 0 && str.indexOf(CH_QUOTE1) < 0 )
+            // Contains " but not ' so print using '-quotes.   
+            proc = escapeProc1 ;
+        return proc ;
+    }
+
+    /** Output a string and run the Runnable at the same indentation level */ 
+    private void writeLexicalSingleLine(AWriter writer, String str, Runnable action) {
+        QuotedStringOutput proc = chooseEscapeProcessor(str) ;
+        proc.writeStr(writer, str); 
+    }
+
+    /** Output a string and run the Runnable at the same indentation level */ 
+    private void writeLexicalMultiLine(AWriter writer, String str, Runnable action) {
+        QuotedStringOutput escapeProc = chooseEscapeProcessor(str) ;
+        int indent = -1 ; 
+        IndentedWriter iw = null ;
+        if ( writer instanceof IndentedWriter ) {
+            iw = (IndentedWriter)writer ;
+            indent = iw.getAbsoluteIndent() ;
+            iw.setAbsoluteIndent(0);
+        }
+        escapeProc.writeStrMultiLine(writer, str) ;
+
+        if ( action != null )
+            action.run();
+        if ( indent >= 0 )
+            iw.setAbsoluteIndent(indent);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/8feb15e6/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
index b7ea21c..bfc10ff 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/TurtleShell.java
@@ -46,6 +46,7 @@ import org.apache.jena.graph.Triple ;
 import org.apache.jena.riot.other.GLib ;
 import org.apache.jena.riot.out.NodeFormatter ;
 import org.apache.jena.riot.out.NodeFormatterTTL ;
+import org.apache.jena.riot.out.NodeFormatterTTL_MultiLine ;
 import org.apache.jena.riot.out.NodeToLabel ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.PrefixMapFactory ;
@@ -60,6 +61,8 @@ import org.apache.jena.vocabulary.RDFS ;
  * Base class to support the pretty forms of Turtle-related languages (Turtle, TriG)
  */
 public abstract class TurtleShell {
+    public static boolean enableMultiLine = false ; 
+    
     protected final IndentedWriter out ;
     protected final NodeFormatter  nodeFmt ;
     protected final PrefixMap      prefixMap ;
@@ -69,7 +72,11 @@ public abstract class TurtleShell {
         this.out = out ;
         if ( pmap == null )
             pmap = PrefixMapFactory.emptyPrefixMap() ;
-        this.nodeFmt = new NodeFormatterTTL(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;
+        if ( ! enableMultiLine )
+            this.nodeFmt = new NodeFormatterTTL(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;
+        else
+            // JENA-1098 - Work-in-progress.
+            this.nodeFmt = new NodeFormatterTTL_MultiLine(baseURI, pmap, NodeToLabel.createScopeByDocument()) ;
         this.prefixMap = pmap ;
         this.baseURI = baseURI ;
     }
@@ -652,11 +659,11 @@ public abstract class TurtleShell {
                     rdfSimpleNodes.add(o) ;
                 }
 
-                if ( rdfLiterals.size() != 0 ) {
+                if ( ! rdfLiterals.isEmpty() ) {
                     writePredicateObjectList(p, rdfLiterals, predicateMaxWidth, first) ;
                     first = false ;
                 }
-                if ( rdfSimpleNodes.size() != 0 ) {
+                if ( ! rdfSimpleNodes.isEmpty() ) {
                     writePredicateObjectList(p, rdfSimpleNodes, predicateMaxWidth, first) ;
                     first = false ;
                 }
@@ -678,13 +685,24 @@ public abstract class TurtleShell {
         private void writePredicateObjectList(Node p, List<Node> objects, int predicateMaxWidth, boolean first) {
             writePredicate(p, predicateMaxWidth, first) ;
             out.incIndent(INDENT_OBJECT) ;
+            
+            boolean lastObjectMultiLine = false ;
             boolean firstObject = true ;
             for ( Node o : objects ) {
-                if ( !firstObject )
-                    out.print(" , ") ;
+                if ( !firstObject ) {
+                    if ( out.getCurrentOffset() > 0 )
+                        out.print(" , ") ;
+                    else
+                        // Before the current indent, due to a multiline literal being written raw.
+                        // We will pad spaces to indent on output spaces.  Don't add a first " " 
+                        out.print(", ") ;
+                }
                 else
                     firstObject = false ;
+                int row1 = out.getRow() ;
                 writeNode(o) ;
+                int row2 = out.getRow();
+                lastObjectMultiLine = (row2 > row1) ;
             }
             out.decIndent(INDENT_OBJECT) ;
         }


[2/4] jena git commit: QuotedStringOutput replaces EscapeProc

Posted by an...@apache.org.
QuotedStringOutput replaces EscapeProc


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/72bcb915
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/72bcb915
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/72bcb915

Branch: refs/heads/master
Commit: 72bcb91525832e8f74d73bd8e6adb76cf5d92f39
Parents: af17137
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Dec 20 17:33:00 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Dec 22 17:32:00 2015 +0000

----------------------------------------------------------------------
 .../apache/jena/riot/out/NodeFormatterNT.java   | 66 +++++++------
 .../apache/jena/riot/out/NodeFormatterTTL.java  | 40 +++++---
 .../riot/out/quoted/QuotedStringOutput.java     | 32 +++++++
 .../riot/out/quoted/QuotedStringOutputBase.java | 52 +++++++++++
 .../riot/out/quoted/QuotedStringOutputNT.java   | 34 +++++++
 .../riot/out/quoted/QuotedStringOutputTTL.java  | 41 +++++++++
 .../quoted/QuotedStringOutputTTL_MultiLine.java | 55 +++++++++++
 .../apache/jena/riot/out/quoted/QuotedURI.java  | 49 ++++++++++
 .../java/org/apache/jena/riot/out/TS_Out.java   |  3 +-
 .../jena/riot/out/TestQuotedStringOutput.java   | 97 ++++++++++++++++++++
 10 files changed, 421 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java
index 5a260c7..c96eb61 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterNT.java
@@ -20,67 +20,65 @@ package org.apache.jena.riot.out;
 
 
 import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.lib.CharSpace ;
+import org.apache.jena.atlas.lib.EscapeStr ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutput ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutputNT ;
+import org.apache.jena.riot.out.quoted.QuotedURI ;
 
 public class NodeFormatterNT extends NodeFormatterBase
 {
     // Formatting for NTriples 
     // Turtles extends this class to intercept forms it can do better.
 
-    private final EscapeProc escapeProc ; 
+    private final QuotedStringOutput quotedStringProc ; 
+    private final QuotedURI quotedUriProc ; 
 
     public NodeFormatterNT() { this(CharSpace.UTF8) ; }
 
-    public NodeFormatterNT(CharSpace charSpace) { escapeProc = new EscapeProc(charSpace) ;}
+    public NodeFormatterNT(CharSpace charSpace) {
+        quotedStringProc = new QuotedStringOutputNT(charSpace);
+        quotedUriProc = new QuotedURI(charSpace) ;
+    }
 
     @Override
-    public void formatURI(AWriter w, String uriStr)
-    {
-        w.print('<') ;
-        escapeProc.writeURI(w, uriStr) ;
-        w.print('>') ;
+    public void formatURI(AWriter w, String uriStr) {
+        quotedUriProc.writeURI(w, uriStr);
     }
 
     @Override
-    public void formatVar(AWriter w, String name)
-    {
-        w.print('?') ;
-        escapeProc.writeStr(w, name) ;
+    public void formatVar(AWriter w, String name) {
+        w.print('?');
+        EscapeStr.stringEsc(w, name, false);
     }
 
     @Override
-    public void formatBNode(AWriter w, String label)
-    {
-        w.print("_:") ;
-        String lab = NodeFmtLib.encodeBNodeLabel(label) ;
-        w.print(lab) ;
+    public void formatBNode(AWriter w, String label) {
+        w.print("_:");
+        String lab = NodeFmtLib.encodeBNodeLabel(label);
+        w.print(lab);
     }
 
     @Override
-    public void formatLitString(AWriter w, String lex)
-    {
-        writeEscaped(w, lex) ;
+    public void formatLitString(AWriter w, String lex) {
+        writeEscaped(w, lex);
     }
 
-    private void writeEscaped(AWriter w, String lex)
-    {
-        w.print('"') ;
-        escapeProc.writeStr(w, lex) ;
-        w.print('"') ;
+    private void writeEscaped(AWriter w, String lex) {
+        quotedStringProc.writeStr(w, lex);
     }
 
     @Override
-    public void formatLitLang(AWriter w, String lex, String langTag)
-    {
-        writeEscaped(w, lex) ;
-        w.print('@') ;
-        w.print(langTag) ;
+    public void formatLitLang(AWriter w, String lex, String langTag) {
+        writeEscaped(w, lex);
+        w.print('@');
+        w.print(langTag);
     }
 
     @Override
-    public void formatLitDT(AWriter w, String lex, String datatypeURI)
-    {
-        writeEscaped(w, lex) ;
-        w.print("^^") ;
-        formatURI(w, datatypeURI) ;
+    public void formatLitDT(AWriter w, String lex, String datatypeURI) {
+        writeEscaped(w, lex);
+        w.print("^^");
+        formatURI(w, datatypeURI);
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java
index c4b2fbe..ca8fabe 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/NodeFormatterTTL.java
@@ -21,6 +21,7 @@ package org.apache.jena.riot.out ;
 import java.net.MalformedURLException ;
 
 import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.atlas.lib.Pair ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
 import org.apache.jena.graph.Node ;
@@ -31,6 +32,7 @@ import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.PrefixMapFactory ;
 import org.apache.jena.riot.system.RiotChars ;
 
+/** Node formatter for Turtle using single line strings */ 
 public class NodeFormatterTTL extends NodeFormatterNT
 {
     private final NodeToLabel nodeToLabel ;
@@ -206,37 +208,49 @@ public class NodeFormatterTTL extends NodeFormatterNT
 
     @Override
     public void formatLitDT(AWriter w, String lex, String datatypeURI) {
+        boolean b = writeLiteralAbbreviated(w, lex, datatypeURI) ;
+        if ( b ) return ;
+        writeLiteralLongForm(w, lex, datatypeURI) ;
+    }
+    
+    protected void writeLiteralLongForm(AWriter w, String lex, String datatypeURI) {
+        writeLiteralOneLine(w, lex, datatypeURI);
+    }
+
+    protected void writeLiteralOneLine(AWriter w, String lex, String datatypeURI) {
+        super.formatLitDT(w, lex, datatypeURI) ;
+    }
+
+    /** Write in a short form, e.g. integer.
+     * @return True if a short form was output else false. 
+     */
+    protected boolean writeLiteralAbbreviated(AWriter w, String lex, String datatypeURI) {
         if ( dtDecimal.equals(datatypeURI) ) {
             if ( validDecimal(lex) ) {
                 w.print(lex) ;
-                return ;
+                return true ;
             }
         } else if ( dtInteger.equals(datatypeURI) ) {
             if ( validInteger(lex) ) {
                 w.print(lex) ;
-                return ;
+                return true ;
             }
-        }
-        if ( dtDouble.equals(datatypeURI) ) {
+        } else if ( dtDouble.equals(datatypeURI) ) {
             if ( validDouble(lex) ) {
                 w.print(lex) ;
-                return ;
+                return true ;
             }
-        }
-        // Boolean
-        if ( dtBoolean.equals(datatypeURI) ) {
+        } else if ( dtBoolean.equals(datatypeURI) ) {
             // We leave "0" and "1" as-is assumign that if written like that,
             // there was a reason.
             if ( lex.equals("true") || lex.equals("false") ) {
                 w.print(lex) ;
-                return ;
+                return true ;
             }
         }
-
-        // else.
-        super.formatLitDT(w, lex, datatypeURI) ;
+        return false ;
     }
-
+    
     private static boolean validInteger(String lex) {
         int N = lex.length() ;
         if ( N == 0 )

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutput.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutput.java b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutput.java
new file mode 100644
index 0000000..35d2968
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutput.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out.quoted;
+
+import org.apache.jena.atlas.io.AWriter ;
+
+/** Interface for writing quoted strings for Turtle, TriG, N-triples and N-Quads */ 
+public interface QuotedStringOutput {
+    public char getQuoteChar() ; 
+    
+    /** Write a string on one line */
+    public void writeStr(AWriter writer, String s) ;
+    
+    /** Write a string, possible on several lines */
+    public void writeStrMultiLine(AWriter writer, String s) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputBase.java b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputBase.java
new file mode 100644
index 0000000..db62bb0
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputBase.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out.quoted;
+
+import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.lib.CharSpace ;
+import org.apache.jena.atlas.lib.EscapeStr ;
+
+/** Quoted strign output - single line, settable quote character and char space. */
+public class QuotedStringOutputBase implements QuotedStringOutput {
+    protected final CharSpace charSpace ;
+    protected final char quoteChar;
+    
+    protected QuotedStringOutputBase(char quoteChar, CharSpace charSpace) {
+        this.charSpace = charSpace ;
+        this.quoteChar = quoteChar ;
+    } 
+
+    @Override
+    public char getQuoteChar() { return quoteChar ; } 
+    
+    @Override
+    public void writeStr(AWriter writer, String str) {
+        // Only " strings in N-Triples/N-Quads
+        writer.print(getQuoteChar());
+        EscapeStr.stringEsc(writer, str, getQuoteChar(), true, charSpace) ;
+        writer.print(getQuoteChar());
+    }
+
+    @Override
+    public void writeStrMultiLine(AWriter writer, String str) {
+        // No multiline strings in N-Triples/N-Quads.
+        writeStr(writer, str) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputNT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputNT.java b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputNT.java
new file mode 100644
index 0000000..ec3c9f5
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputNT.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out.quoted;
+
+import org.apache.jena.atlas.lib.CharSpace ;
+import org.apache.jena.atlas.lib.Chars ;
+
+/** Escape processor for N-Triples/N-Quads */
+public class QuotedStringOutputNT extends QuotedStringOutputBase {
+    
+    public QuotedStringOutputNT() {
+        this(CharSpace.UTF8) ;
+    }
+    
+    public QuotedStringOutputNT(CharSpace charSpace) {
+        super(Chars.CH_QUOTE2, charSpace) ; 
+    } 
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL.java b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL.java
new file mode 100644
index 0000000..0ac1257
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out.quoted;
+
+import org.apache.jena.atlas.lib.CharSpace ;
+import org.apache.jena.atlas.lib.Chars ;
+
+/** Escape processor for Turtle. */
+public class QuotedStringOutputTTL extends QuotedStringOutputBase {
+
+    public QuotedStringOutputTTL() {
+        this(Chars.CH_QUOTE2, CharSpace.UTF8) ;
+    }
+
+    /** Always use the given quote character (0 means use " or ' as needed) */
+    public QuotedStringOutputTTL(char quoteChar) {
+        this(quoteChar, CharSpace.UTF8) ;
+    }
+    
+    /** Turtle is UTF-8 : ASCII is for non-standard needs */
+    protected QuotedStringOutputTTL(char quoteChar, CharSpace charSpace) {
+        super(quoteChar, charSpace) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL_MultiLine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL_MultiLine.java b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL_MultiLine.java
new file mode 100644
index 0000000..1f8d869
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedStringOutputTTL_MultiLine.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out.quoted;
+
+import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.lib.CharSpace ;
+import org.apache.jena.atlas.lib.EscapeStr ;
+
+public class QuotedStringOutputTTL_MultiLine extends QuotedStringOutputTTL {
+
+    public QuotedStringOutputTTL_MultiLine() {
+        super() ;
+    }
+
+    /** Always use the given quote character */
+    public QuotedStringOutputTTL_MultiLine(char quoteChar) {
+        super(quoteChar) ;
+    }
+    
+    /** Turtle is UTF-8 : ASCII is for non-standard needs */
+    protected QuotedStringOutputTTL_MultiLine(char quoteChar, CharSpace charSpace) {
+        super(quoteChar, charSpace) ;
+    } 
+    
+    /** Write a string using triple quotes. Try to avoid escapes by looking for the quote character first. */
+    @Override
+    public void writeStrMultiLine(AWriter w, String s) {
+        quote3(w) ;
+        EscapeStr.stringEsc(w, s, quoteChar, false, charSpace); 
+        quote3(w) ;
+    }
+    
+    private void quote3(AWriter w) {
+        w.print(quoteChar) ;
+        w.print(quoteChar) ;
+        w.print(quoteChar) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedURI.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedURI.java b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedURI.java
new file mode 100644
index 0000000..3d0292e
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/out/quoted/QuotedURI.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out.quoted;
+
+import org.apache.jena.atlas.io.AWriter ;
+import org.apache.jena.atlas.lib.CharSpace ;
+import org.apache.jena.atlas.lib.Chars ;
+import org.apache.jena.atlas.lib.EscapeStr ;
+
+public class QuotedURI {
+    private final CharSpace charSpace ;
+
+    public QuotedURI() {
+        this(CharSpace.UTF8) ;
+    }
+    
+    public QuotedURI(CharSpace charSpace) {
+        this.charSpace = charSpace ; 
+    } 
+    
+    /** Write a string for a URI on one line. */
+    public void writeURI(AWriter w, String s) {
+        // URIs do not have an escape mechanism. %-is an encoding.
+        // We can either print as-is or convert to %-encoding.
+        // (Ignoring host names which be in puny code).
+        w.print(Chars.CH_LT);
+        if ( CharSpace.isAscii(charSpace) )
+            EscapeStr.writeASCII(w, s) ;
+        else
+            w.print(s) ;
+        w.print(Chars.CH_GT);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/test/java/org/apache/jena/riot/out/TS_Out.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/out/TS_Out.java b/jena-arq/src/test/java/org/apache/jena/riot/out/TS_Out.java
index a093312..f13735c 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/out/TS_Out.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/out/TS_Out.java
@@ -24,7 +24,8 @@ import org.junit.runners.Suite ;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses( {
-      TestNodeFmt.class
+    TestQuotedStringOutput.class
+    , TestNodeFmt.class
     , TestNodeFmtLib.class
 })
 

http://git-wip-us.apache.org/repos/asf/jena/blob/72bcb915/jena-arq/src/test/java/org/apache/jena/riot/out/TestQuotedStringOutput.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/out/TestQuotedStringOutput.java b/jena-arq/src/test/java/org/apache/jena/riot/out/TestQuotedStringOutput.java
new file mode 100644
index 0000000..6336ddd
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/riot/out/TestQuotedStringOutput.java
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.out;
+
+import static org.junit.Assert.assertEquals ;
+
+import org.apache.jena.atlas.io.StringWriterI ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutput ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutputNT ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutputTTL ;
+import org.apache.jena.riot.out.quoted.QuotedStringOutputTTL_MultiLine ;
+import org.junit.Test ;
+
+public class TestQuotedStringOutput {
+
+    static void testSingleLine(QuotedStringOutput proc, String input, String expected) {
+        StringWriterI w = new StringWriterI() ;
+        proc.writeStr(w, input);
+        String output = w.toString() ;
+        expected = proc.getQuoteChar()+expected+proc.getQuoteChar() ;
+        assertEquals(expected, output) ;
+    }
+    
+    static void testMultiLine(QuotedStringOutput proc, String input, String expected) {
+        StringWriterI w = new StringWriterI() ;
+        proc.writeStrMultiLine(w, input);
+        String output = w.toString() ;
+        assertEquals(expected, output) ;
+    }
+    
+    private QuotedStringOutput escProcNT = new QuotedStringOutputNT() ;
+    private QuotedStringOutput escProcTTL_S2 = new QuotedStringOutputTTL('"') ;
+    private QuotedStringOutput escProcTTL_S1 = new QuotedStringOutputTTL('\'') ;
+    
+    private QuotedStringOutput escProcTTL_M2 = new QuotedStringOutputTTL_MultiLine('"') ;
+    private QuotedStringOutput escProcTTL_M1 = new QuotedStringOutputTTL_MultiLine('\'') ;
+    
+    @Test public void escape_nt_00() { testSingleLine(escProcNT, "", "") ; }
+    @Test public void escape_nt_01() { testSingleLine(escProcNT, "abc", "abc") ; }
+    @Test public void escape_nt_02() { testSingleLine(escProcNT, "abc\ndef", "abc\\ndef") ; }
+    
+    @Test public void escape_nt_03() { testSingleLine(escProcNT, "\"", "\\\"") ; }
+    @Test public void escape_nt_04() { testSingleLine(escProcNT, "'", "'") ; }
+    @Test public void escape_nt_05() { testSingleLine(escProcNT, "xyz\t", "xyz\\t") ; }
+    
+    @Test public void escape_ttl_singleline_quote2_00() { testSingleLine(escProcTTL_S2, "", "") ; }
+    @Test public void escape_ttl_singleline_quote2_01() { testSingleLine(escProcTTL_S2, "abc", "abc") ; }
+    @Test public void escape_ttl_singleline_quote2_02() { testSingleLine(escProcTTL_S2, "abc\ndef", "abc\\ndef") ; }
+    
+    @Test public void escape_ttl_singleline_quote2_03() { testSingleLine(escProcTTL_S2, "\"", "\\\"") ; }
+    @Test public void escape_ttl_singleline_quote2_04() { testSingleLine(escProcTTL_S2, "'", "'") ; }
+    @Test public void escape_ttl_singleline_quote2_05() { testSingleLine(escProcTTL_S2, "xyz\t", "xyz\\t") ; }
+    
+    @Test public void escape_ttl_singleline_quote1_00() { testSingleLine(escProcTTL_S1, "", "") ; }
+    @Test public void escape_ttl_singleline_quote1_01() { testSingleLine(escProcTTL_S1, "abc", "abc") ; }
+    @Test public void escape_ttl_singleline_quote1_02() { testSingleLine(escProcTTL_S1, "abc\ndef", "abc\\ndef") ; }
+    
+    @Test public void escape_ttl_singleline_quote1_03() { testSingleLine(escProcTTL_S1, "\"", "\"") ; }
+    @Test public void escape_ttl_singleline_quote1_04() { testSingleLine(escProcTTL_S1, "'", "\\'") ; }
+    @Test public void escape_ttl_singleline_quote1_05() { testSingleLine(escProcTTL_S1, "xyz\t", "xyz\\t") ; }
+    
+    // Multiple with single line output processor.
+    @Test public void escape_ttl_singleline_quote2_multiline_str0() { testMultiLine(escProcTTL_S2, "", "\"\"") ; }
+    @Test public void escape_ttl_singleline_quote2_multiline_str1() { testMultiLine(escProcTTL_S2, "abc", "\"abc\"") ; }
+    @Test public void escape_ttl_singleline_quote2_multiline_str2() { testMultiLine(escProcTTL_S2, "abc\ndef", "\"abc\\ndef\"") ; }
+    
+    @Test public void escape_ttl_singleline_quote2_multiline_str3() { testMultiLine(escProcTTL_S2, "\"", "\"\\\"\"") ; }
+    @Test public void escape_ttl_singleline_quote2_multiline_str4() { testMultiLine(escProcTTL_S2, "'", "\"'\"") ; }
+    @Test public void escape_ttl_singleline_quote2_multiline_str5() { testMultiLine(escProcTTL_S2, "xyz\t", "\"xyz\\t\"") ; }
+    
+    // Multiple with single line output processor.
+    @Test public void escape_ttl_singleline_quote1_multiline_str0() { testMultiLine(escProcTTL_S1, "", "''") ; }
+    @Test public void escape_ttl_singleline_quote1_multiline_str1() { testMultiLine(escProcTTL_S1, "abc", "'abc'") ; }
+    @Test public void escape_ttl_singleline_quote1_multiline_str2() { testMultiLine(escProcTTL_S1, "abc\ndef", "'abc\\ndef'") ; }
+    
+    @Test public void escape_ttl_singleline_quote1_multiline_str3() { testMultiLine(escProcTTL_S1, "\"", "'\"'") ; }
+    @Test public void escape_ttl_singleline_quote1_multiline_str4() { testMultiLine(escProcTTL_S1, "'", "'\\''") ; }
+    @Test public void escape_ttl_singleline_quote1_multiline_str5() { testMultiLine(escProcTTL_S1, "xyz\t", "'xyz\\t'") ; }
+
+    // Multiline, multiline
+}


[4/4] jena git commit: Move CharSpace to jena-base. Clean up string escape processing.

Posted by an...@apache.org.
Move CharSpace to jena-base.  Clean up string escape processing.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/af171371
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/af171371
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/af171371

Branch: refs/heads/master
Commit: af171371bc723f830060345dd9a4758b4ebf8d6f
Parents: 8e615f1
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Dec 20 17:31:55 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Dec 22 17:32:00 2015 +0000

----------------------------------------------------------------------
 .../org/apache/jena/riot/RDFWriterRegistry.java |   2 +-
 .../org/apache/jena/riot/lang/RiotParsers.java  |   7 +-
 .../org/apache/jena/riot/out/CharSpace.java     |  22 ---
 .../org/apache/jena/riot/out/EscapeProc.java    |  49 ------
 .../apache/jena/riot/system/StreamRDFLib.java   |   2 +-
 .../jena/riot/system/StreamRDFWriter.java       |   2 +-
 .../apache/jena/riot/writer/NQuadsWriter.java   |   2 +-
 .../apache/jena/riot/writer/NTriplesWriter.java |   6 +-
 .../jena/riot/writer/WriterStreamRDFPlain.java  |   2 +-
 .../apache/jena/riot/lang/TestLangNTriples.java |   7 +-
 .../apache/jena/riot/lang/TestLangNTuples.java  |  18 +--
 .../org/apache/jena/riot/out/TestNodeFmt.java   |  13 ++
 .../org/apache/jena/atlas/lib/CharSpace.java    |  28 ++++
 .../org/apache/jena/atlas/lib/EscapeStr.java    | 149 +++++++++++--------
 .../java/org/apache/jena/atlas/lib/TS_Lib.java  |   2 +-
 .../apache/jena/atlas/lib/TestEscapeStr.java    |  40 +++++
 16 files changed, 195 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java b/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
index 101b459..918d03f 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
@@ -20,8 +20,8 @@ package org.apache.jena.riot;
 
 import java.util.* ;
 
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.n3.N3JenaWriter ;
-import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.out.JsonLDWriter ;
 import org.apache.jena.riot.system.RiotLib ;
 import org.apache.jena.riot.thrift.WriterDatasetThrift ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/lang/RiotParsers.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/lang/RiotParsers.java b/jena-arq/src/main/java/org/apache/jena/riot/lang/RiotParsers.java
index 6953df9..8f5ccda 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/lang/RiotParsers.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/lang/RiotParsers.java
@@ -32,9 +32,12 @@ import java.io.Reader ;
 
 import org.apache.jena.atlas.io.PeekReader ;
 import org.apache.jena.atlas.json.io.parser.TokenizerJSON ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.riot.* ;
-import org.apache.jena.riot.out.CharSpace ;
-import org.apache.jena.riot.system.* ;
+import org.apache.jena.riot.system.ErrorHandlerFactory ;
+import org.apache.jena.riot.system.ParserProfile ;
+import org.apache.jena.riot.system.RiotLib ;
+import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.riot.tokens.Tokenizer ;
 import org.apache.jena.riot.tokens.TokenizerFactory ;
 

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/out/CharSpace.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/CharSpace.java b/jena-arq/src/main/java/org/apache/jena/riot/out/CharSpace.java
deleted file mode 100644
index bff34be..0000000
--- a/jena-arq/src/main/java/org/apache/jena/riot/out/CharSpace.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.riot.out;
-
-/** rather write 'true' or 'false', use this enum */ 
-public enum CharSpace{ ASCII, UTF8 }

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/out/EscapeProc.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/out/EscapeProc.java b/jena-arq/src/main/java/org/apache/jena/riot/out/EscapeProc.java
deleted file mode 100644
index ae6386a..0000000
--- a/jena-arq/src/main/java/org/apache/jena/riot/out/EscapeProc.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.riot.out;
-
-import org.apache.jena.atlas.io.AWriter ;
-import org.apache.jena.atlas.lib.EscapeStr ;
-
-public class EscapeProc {
-    private final boolean ascii ;
-
-    public EscapeProc(CharSpace charSpace) {
-        this.ascii = ( charSpace == CharSpace.ASCII ) ; 
-    } 
-
-    public void writeURI(AWriter w, String s) {
-        if ( ascii )
-            EscapeStr.stringEsc(w, s, true, ascii) ;
-        else
-            // It's a URI - assume legal.
-            w.print(s) ;
-    }
-
-    public void writeStr(AWriter w, String s) {
-        EscapeStr.stringEsc(w, s, true, ascii) ;
-    }
-
-    public void writeStrMultiLine(AWriter w, String s) {
-        // N-Triples does not have """
-        EscapeStr.stringEsc(w, s, false, ascii) ;
-    }
-
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java b/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
index 92aa8a8..9f6ecb1 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
@@ -23,12 +23,12 @@ import java.io.Writer ;
 
 import org.apache.jena.atlas.io.AWriter ;
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.riot.lang.StreamRDFCounting ;
-import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.writer.WriterStreamRDFPlain ;
 import org.apache.jena.shared.JenaException ;
 import org.apache.jena.shared.PrefixMapping ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
index 6448e42..b70dbf8 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFWriter.java
@@ -26,10 +26,10 @@ import java.util.Map ;
 
 import org.apache.jena.atlas.io.AWriter ;
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.riot.* ;
-import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.thrift.BinRDF ;
 import org.apache.jena.riot.writer.StreamWriterTriX ;
 import org.apache.jena.riot.writer.WriterStreamRDFBlocks ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
index 3a74bcf..56e30a0 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
@@ -22,8 +22,8 @@ import java.io.OutputStream ;
 import java.io.Writer ;
 import java.util.Iterator ;
 
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
index f6d3047..491611a 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
@@ -18,18 +18,16 @@
 
 package org.apache.jena.riot.writer;
 
-import static org.apache.jena.riot.out.CharSpace.ASCII ;
-import static org.apache.jena.riot.out.CharSpace.UTF8 ;
-
 import java.io.OutputStream ;
 import java.io.Writer ;
 import java.util.Iterator ;
 
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.CharSpace ;
+import static org.apache.jena.atlas.lib.CharSpace.* ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamOps ;
 import org.apache.jena.riot.system.StreamRDF ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFPlain.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFPlain.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFPlain.java
index 13401f0..7147789 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFPlain.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/WriterStreamRDFPlain.java
@@ -20,9 +20,9 @@ package org.apache.jena.riot.writer ;
 
 import org.apache.jena.atlas.io.AWriter ;
 import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
-import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.out.NodeFormatter ;
 import org.apache.jena.riot.out.NodeFormatterNT ;
 import org.apache.jena.riot.system.StreamRDF ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java b/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
index 8306786..18112fb 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
@@ -20,14 +20,17 @@ package org.apache.jena.riot.lang;
 
 import java.io.StringReader ;
 
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.riot.* ;
 import org.apache.jena.riot.ErrorHandlerTestLib.ErrorHandlerEx ;
 import org.apache.jena.riot.ErrorHandlerTestLib.ExFatal ;
-import org.apache.jena.riot.out.CharSpace;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.RiotException ;
 import org.apache.jena.riot.system.StreamRDFLib ;
 import org.apache.jena.riot.tokens.Tokenizer ;
 import org.apache.jena.sparql.sse.SSE ;

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java b/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
index ced99bd..d06047f 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
@@ -18,16 +18,20 @@
 
 package org.apache.jena.riot.lang;
 
+import static org.apache.jena.riot.system.ErrorHandlerFactory.errorHandlerNoLogging ;
+import static org.apache.jena.riot.system.ErrorHandlerFactory.getDefaultErrorHandler ;
+import static org.apache.jena.riot.system.ErrorHandlerFactory.setDefaultErrorHandler ;
+
 import java.io.ByteArrayInputStream ;
 
 import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.riot.ErrorHandlerTestLib.ErrorHandlerEx;
 import org.apache.jena.riot.ErrorHandlerTestLib.ExError;
 import org.apache.jena.riot.ErrorHandlerTestLib.ExFatal;
 import org.apache.jena.riot.ErrorHandlerTestLib.ExWarning;
 import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.out.CharSpace;
 import org.apache.jena.riot.system.ErrorHandler ;
 import org.apache.jena.riot.system.RiotLib ;
 import org.apache.jena.riot.system.StreamRDFLib ;
@@ -36,9 +40,6 @@ import org.apache.jena.riot.tokens.TokenizerFactory ;
 import org.junit.AfterClass ;
 import org.junit.BeforeClass ;
 import org.junit.Test ;
-import static org.apache.jena.riot.system.ErrorHandlerFactory.errorHandlerNoLogging ;
-import static org.apache.jena.riot.system.ErrorHandlerFactory.getDefaultErrorHandler ;
-import static org.apache.jena.riot.system.ErrorHandlerFactory.setDefaultErrorHandler ;
 /** Test of syntax by a tuples parser (does not include node validitiy checking) */ 
 
 abstract public class TestLangNTuples extends BaseTest
@@ -178,7 +179,7 @@ abstract public class TestLangNTuples extends BaseTest
         Tokenizer tokenizer = charSpace == CharSpace.ASCII ? TokenizerFactory.makeTokenizerASCII(in) : TokenizerFactory.makeTokenizerUTF8(in) ;
         return tokenizer ;
     }
-//    
+    
     static protected Tokenizer tokenizer(String string)
     {
         // UTF-8
@@ -198,15 +199,10 @@ abstract public class TestLangNTuples extends BaseTest
         x.setProfile(RiotLib.profile(null, false, true, new ErrorHandlerEx())) ;
         x.parse() ;
     }
-//    
+    
     protected abstract Lang getLang() ;
     
     protected long parseCount(String... strings) {
         return ParserTestBaseLib.parseCount(getLang(), strings) ;
     }
-    
-//    protected void parseCheck(String... strings) {
-//        ParserTestBaseLib.parseCount(getLang(), strings) ;
-//    }
-
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-arq/src/test/java/org/apache/jena/riot/out/TestNodeFmt.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/out/TestNodeFmt.java b/jena-arq/src/test/java/org/apache/jena/riot/out/TestNodeFmt.java
index 97db092..8f917ee 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/out/TestNodeFmt.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/out/TestNodeFmt.java
@@ -21,6 +21,7 @@ package org.apache.jena.riot.out;
 import org.apache.jena.JenaRuntime ;
 import org.apache.jena.atlas.io.StringWriterI ;
 import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.lib.CharSpace ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.PrefixMapFactory ;
@@ -184,4 +185,16 @@ public class TestNodeFmt extends BaseTest
     @Test public void nodefmt_ttl_74()  { test(nodeFormatterTTL, "'False'^^<http://www.w3.org/2001/XMLSchema#boolean>", "\"False\"^^<http://www.w3.org/2001/XMLSchema#boolean>") ; }
     @Test public void nodefmt_ttl_75()  { test(nodeFormatterTTL, "'True'^^<http://www.w3.org/2001/XMLSchema#boolean>", "\"True\"^^<http://www.w3.org/2001/XMLSchema#boolean>") ; }
     
+    private static String QuoteDouble3 = "\"\"\"" ;
+    private static String QuoteSingle3 = "'''" ;
+
+    // Multiline
+    
+    private static NodeFormatter nodeFormatterTTL_ML = new NodeFormatterTTL_MultiLine(base, prefixMap) ;
+    
+    @Test public void nodefmt_ttl_ML_01()  { test(nodeFormatterTTL_ML, "'A\\nB'", QuoteDouble3+"A\nB"+QuoteDouble3) ; }
+    @Test public void nodefmt_ttl_ML_02()  { test(nodeFormatterTTL_ML, "'A\\nB'@en", QuoteDouble3+"A\nB"+QuoteDouble3+"@en") ; }
+    @Test public void nodefmt_ttl_ML_03()  { test(nodeFormatterTTL_ML, "'A\\nB'^^:ex\\/datatype", QuoteDouble3+"A\nB"+QuoteDouble3+"^^ex:datatype") ; }
+
+    
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-base/src/main/java/org/apache/jena/atlas/lib/CharSpace.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/CharSpace.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/CharSpace.java
new file mode 100644
index 0000000..8268aa3
--- /dev/null
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/CharSpace.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.atlas.lib;
+
+/** rather write 'true' or 'false', use this enum */ 
+public enum CharSpace {
+    ASCII, UTF8;
+
+    public static boolean isAscii(CharSpace charSpace) {
+        return charSpace == ASCII;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-base/src/main/java/org/apache/jena/atlas/lib/EscapeStr.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/EscapeStr.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/EscapeStr.java
index fb5edf9..593c019 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/lib/EscapeStr.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/EscapeStr.java
@@ -20,86 +20,115 @@ package org.apache.jena.atlas.lib;
 
 import org.apache.jena.atlas.AtlasException ;
 import org.apache.jena.atlas.io.AWriter ;
-import org.apache.jena.atlas.io.IndentedLineBuffer ;
 import org.apache.jena.atlas.io.OutputUtils ;
+import org.apache.jena.atlas.io.StringWriterI ;
 
+/** String escape utilities */
 public class EscapeStr
 {
-    // Tests: TestOutput
-    // See also OutputLangUtils.outputEsc.
-//    private final boolean ascii ;
-//
-//    public EscapeStr(CharSpace charSpace) { this.ascii = ( charSpace == CharSpace.ASCII ) ; } 
-//
-//    public void writeURI(AWriter w, String s)
-//    {
-//        if ( ascii )
-//            stringEsc(w, s, true, ascii) ;
-//        else
-//            // It's a URI - assume legal.
-//            w.print(s) ;
-//    }
-//
-//    public void writeStr(AWriter w, String s) 
-//    {
-//        stringEsc(w, s, true, ascii) ;
-//    }
-//
-//    public void writeStrMultiLine(AWriter w, String s) 
-//    {
-//        // N-Triples does not have """
-//        stringEsc(w, s, false, ascii) ;
-//    }
-//
-    // Utility
     /*
      * Escape characters in a string according to Turtle rules. 
      */
-    public static String stringEsc(String s)
-    { return stringEsc(s, true, false) ; }
-
-    private static String stringEsc(String s, boolean singleLineString, boolean asciiOnly)
-    {
-        IndentedLineBuffer sb = new IndentedLineBuffer() ;
-        stringEsc(sb, s, singleLineString, asciiOnly) ;
-        return sb.toString() ;
+    public static String stringEsc(String s) {
+        AWriter w = new StringWriterI() ;
+        stringEsc(w, s, Chars.CH_QUOTE2, true, CharSpace.UTF8) ;
+        return w.toString() ;
     }
 
-    public static void stringEsc(AWriter out, String s, boolean singleLineString, boolean asciiOnly)
-    {
+    /** Write a string - basic escaping, no quote escaping. */
+    public static void stringEsc(AWriter out, String s, boolean asciiOnly) {
         int len = s.length() ;
         for (int i = 0; i < len; i++) {
             char c = s.charAt(i);
-
             // \\ Escape always possible.
-            if (c == '\\') 
-            {
+            if (c == '\\') {
                 out.print('\\') ;
                 out.print(c) ;
                 continue ;
             }
-            if ( singleLineString )
-            {
-                if ( c == '"' )         { out.print("\\\""); continue ; }
-                else if (c == '\n')     { out.print("\\n");  continue ; }
-                else if (c == '\t')     { out.print("\\t");  continue ; }
-                else if (c == '\r')     { out.print("\\r");  continue ; }
-                else if (c == '\f')     { out.print("\\f");  continue ; }
+            switch(c) {
+                case '\n':  out.print("\\n"); continue; 
+                case '\t':  out.print("\\t"); continue; 
+                case '\r':  out.print("\\r"); continue; 
+                case '\f':  out.print("\\f"); continue; 
+                default:    // Drop through
             }
-            // Not \-style esacpe. 
-            if ( c >= 32 && c < 127 )
-                out.print(c);
-            else if ( !asciiOnly )
+            if ( !asciiOnly )
                 out.print(c);
-            else
-            {
-                // Outside the charset range.
-                // Does not cover beyond 16 bits codepoints directly
-                // (i.e. \U escapes) but Java keeps these as surrogate
-                // pairs and will print as characters
-                out.print( "\\u") ;
-                OutputUtils.printHex(out, c, 4) ;
+            else 
+                writeCharAsASCII(out, c) ;
+        }
+    }
+    
+    public static void stringEsc(AWriter out, String s, char quoteChar, boolean singleLineString) {
+        stringEsc(out, s, quoteChar, singleLineString, CharSpace.UTF8);
+    }
+    
+    public static void stringEsc(AWriter out, String s, char quoteChar, boolean singleLineString, CharSpace charSpace) {
+        boolean ascii = ( CharSpace.ASCII == charSpace ) ;
+        int len = s.length() ;
+        int quotesInARow = 0 ;
+        for (int i = 0; i < len; i++) {
+            char c = s.charAt(i);
+            // \\ Escape always possible.
+            if (c == '\\') {
+                out.print('\\') ;
+                out.print(c) ;
+                continue ;
+            }
+            if ( ! singleLineString ) {
+                // Multiline string.
+                if ( c == quoteChar ) {
+                    quotesInARow++ ;
+                    if ( quotesInARow == 3 ) {
+                        out.print("\\");
+                        out.print(quoteChar);
+                        quotesInARow = 0; 
+                        continue;
+                    }
+                } else {
+                    quotesInARow = 0 ;
+                }
+            } else {
+                if ( c == quoteChar ) {
+                    out.print("\\"); out.print(c) ; continue ;
+                }
+                switch(c) {
+                    case '\n':  out.print("\\n"); continue; 
+                    case '\t':  out.print("\\t"); continue; 
+                    case '\r':  out.print("\\r"); continue; 
+                    case '\f':  out.print("\\f"); continue; 
+                    default:    // Drop through
+                }
             }
+
+            if ( !ascii )
+                out.print(c);
+            else 
+                writeCharAsASCII(out, c) ;
+        }
+    }
+
+    /** Write a string with Unicode to ASCII conversion using \-u escapes */  
+    public static void writeASCII(AWriter out, String s) {
+        int len = s.length() ;
+        for (int i = 0; i < len; i++) {
+            char c = s.charAt(i);
+            writeCharAsASCII(out, c);
+        }
+    }
+
+    /** Write a character with Unicode to ASCII conversion using \-u escapes */
+    public static void writeCharAsASCII(AWriter out, char c) {
+        if ( c >= 32 && c < 127 )
+            out.print(c);
+        else {
+            // Outside the charset range.
+            // Does not cover beyond 16 bits codepoints directly
+            // (i.e. \U escapes) but Java keeps these as surrogate
+            // pairs and will print as characters
+            out.print("\\u") ;
+            OutputUtils.printHex(out, c, 4) ;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-base/src/test/java/org/apache/jena/atlas/lib/TS_Lib.java
----------------------------------------------------------------------
diff --git a/jena-base/src/test/java/org/apache/jena/atlas/lib/TS_Lib.java b/jena-base/src/test/java/org/apache/jena/atlas/lib/TS_Lib.java
index a67532b..bd3d027 100644
--- a/jena-base/src/test/java/org/apache/jena/atlas/lib/TS_Lib.java
+++ b/jena-base/src/test/java/org/apache/jena/atlas/lib/TS_Lib.java
@@ -25,7 +25,6 @@ import org.junit.runners.Suite ;
 
 /**
  * Tests for the Atlas lib package
- *
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses( {
@@ -33,6 +32,7 @@ import org.junit.runners.Suite ;
     , TestBitsLong.class
     , TestBitsInt.class
     , TestBytes.class
+    , TestEscapeStr.class
     , TestHex.class
     , TestListUtils.class
     , TestSetUtils.class

http://git-wip-us.apache.org/repos/asf/jena/blob/af171371/jena-base/src/test/java/org/apache/jena/atlas/lib/TestEscapeStr.java
----------------------------------------------------------------------
diff --git a/jena-base/src/test/java/org/apache/jena/atlas/lib/TestEscapeStr.java b/jena-base/src/test/java/org/apache/jena/atlas/lib/TestEscapeStr.java
new file mode 100644
index 0000000..7f4ab95
--- /dev/null
+++ b/jena-base/src/test/java/org/apache/jena/atlas/lib/TestEscapeStr.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.atlas.lib;
+
+import org.junit.Assert ;
+import org.junit.Test ;
+
+// Testing is a bit light here but the RDF term output and 
+// the language level output covers the ground as well.
+// See TestQuotedString in ARQ.
+
+public class TestEscapeStr {
+    
+    @Test public void escape_str_01()   { test("", "") ; }
+    @Test public void escape_str_02()   { test("A", "A") ; }
+    @Test public void escape_str_03()   { test("\n", "\\n") ; }
+    @Test public void escape_str_04()   { test("A\tB", "A\\tB") ; }
+    @Test public void escape_str_05()   { test("\"", "\\\"") ; }
+
+    private void test(String input, String expected) {
+        String output = EscapeStr.stringEsc(input) ;
+        Assert.assertEquals(expected, output);
+    }
+}