3 namespace Wikimedia\Purtle;
6 * Helper class for quoting literals and URIs in N3 output.
7 * Optionally supports shorthand and prefix resolution.
10 * @author Daniel Kinzler
17 private $escaper = null;
20 * @param bool $escapeUnicode
22 public function setEscapeUnicode( $escapeUnicode ) {
23 $this->escaper = $escapeUnicode ? new UnicodeEscaper() : null;
26 public function escapeIRI( $iri ) {
27 //FIXME: apply unicode escaping?!
42 public function escapeLiteral( $s ) {
43 // String escapes. Note that the N3 spec is more restrictive than the Turtle and TR
44 // specifications, see <https://www.w3.org/TeamSubmission/n3/#escaping>
45 // and <https://www.w3.org/TR/turtle/#string>
46 // and <https://www.w3.org/TR/n-triples/#grammar-production-literal>.
47 // Allowed escapes according to the N3 spec are:
48 // ECHAR ::= '\' [tbnrf"'\]
49 // The single quote however does not require escaping when used in double quotes.
50 $escaped = strtr( $s, [
87 if ( $this->escaper !== null ) {
88 $escaped = $this->escaper->escapeString( $escaped );