From: <cw...@us...> - 2007-08-13 15:59:48
|
Revision: 516 http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=516&view=rev Author: cweiske Date: 2007-08-13 08:59:46 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Make serializing a bit more intelligent when quoting Modified Paths: -------------- trunk/rdfapi-php/api/syntax/N3Serializer.php Modified: trunk/rdfapi-php/api/syntax/N3Serializer.php =================================================================== --- trunk/rdfapi-php/api/syntax/N3Serializer.php 2007-08-13 15:43:35 UTC (rev 515) +++ trunk/rdfapi-php/api/syntax/N3Serializer.php 2007-08-13 15:59:46 UTC (rev 516) @@ -410,11 +410,26 @@ if (is_a($o, 'Literal')) { $l = $o->getLabel(); - if ( strpos($l, LINEFEED) === FALSE ) { - $out.="\"$l\""; + if (strpos($l, LINEFEED) === false) { + $long = false; } else { - $out.="\"\"\"$l\"\"\""; + $long = true; } + + //try to be intelligent + $quoteSingle = strpos($l, '\'') !== false; + $quoteDouble = strpos($l, '"') !== false; + if ($quoteSingle && !$quoteDouble) { + $quoteChar = $long ? '"""' : '"'; + } else if ($quoteDouble && !$quoteSingle) { + $quoteChar = $long ? '\'\'\'' : '\''; + } else { + //both quotation chars inside + $quoteChar = $long ? '"""' : '"'; + $l = addslashes($l); + } + $out .= $quoteChar . $l . $quoteChar; + if ( $o->getLanguage()!='' ) { $out.='@'.$o->getLanguage(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |