Author: dajobe
Date: Thu Jan 17 05:22:57 2008
New Revision: 13611

URL: http://svn.librdf.org/view?rev=3D13611&view=3Drev
Log:
(raptor_iostream_write_string_python): Add Long Turtle mode 2, shift JSON t=
o 3. (raptor_turtle_writer_quoted_counted_string): Use mode 2 for triple-qu=
oted long strings

Modified:
    raptor/trunk/src/raptor_turtle_writer.c

Modified: raptor/trunk/src/raptor_turtle_writer.c
URL: http://svn.librdf.org/view/raptor/trunk/src/raptor_turtle_writer.c?rev=
=3D13611&r1=3D13610&r2=3D13611&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- raptor/trunk/src/raptor_turtle_writer.c (original)
+++ raptor/trunk/src/raptor_turtle_writer.c Thu Jan 17 05:22:57 2008
@@ -384,7 +384,7 @@
  * @len: length of UTF-8 string
  * @delim: Terminating delimiter character for string (such as " or >)
  * or \0 for no escaping.
- * @flags: flags 0=3DN-Triples mode, 1=3DTurtle (allow raw UTF-8), 2=3DJSON
+ * @flags: flags 0=3DN-Triples mode, 1=3DTurtle (allow raw UTF-8), 2=3DTur=
tle long string (allow raw UTF-8), 3=3DJSON
  *
  * Write a UTF-8 string using Python-style escapes (N-Triples, Turtle, JSO=
N) to an iostream.
  * =

@@ -401,7 +401,7 @@
   int unichar_len;
   raptor_unichar unichar;
 =

-  if(flags < 0 || flags > 2)
+  if(flags < 0 || flags > 3)
     return 1;
   =

   for(; (c=3D*string); string++, len--) {
@@ -417,32 +417,40 @@
       continue;
     }
     =

-    /* Note: NTriples is ASCII */
-    if(c =3D=3D 0x09) {
-      raptor_iostream_write_counted_string(iostr, "\\t", 2);
-      continue;
-    } else if((flags =3D=3D 2) && c =3D=3D 0x08) {
-      /* JSON has \b for backspace */
-      raptor_iostream_write_counted_string(iostr, "\\b", 2);
-      continue;
-    } else if(c =3D=3D 0x0a) {
-      raptor_iostream_write_counted_string(iostr, "\\n", 2);
-      continue;
-    } else if((flags =3D=3D 2) && c =3D=3D 0x0b) {
-      /* JSON has \f for formfeed */
-      raptor_iostream_write_counted_string(iostr, "\\f", 2);
-      continue;
-    } else if(c =3D=3D 0x0d) {
-      raptor_iostream_write_counted_string(iostr, "\\r", 2);
-      continue;
-    } else if(c < 0x20|| c =3D=3D 0x7f) {
-      raptor_iostream_write_counted_string(iostr, "\\u", 2);
-      raptor_iostream_format_hexadecimal(iostr, c, 4);
-      continue;
+    if(flags !=3D 2) {
+      /* N-Triples, Turtle or JSON */
+
+      /* Note: NTriples is ASCII */
+      if(c =3D=3D 0x09) {
+        raptor_iostream_write_counted_string(iostr, "\\t", 2);
+        continue;
+      } else if((flags =3D=3D 3) && c =3D=3D 0x08) {
+        /* JSON has \b for backspace */
+        raptor_iostream_write_counted_string(iostr, "\\b", 2);
+        continue;
+      } else if(c =3D=3D 0x0a) {
+        raptor_iostream_write_counted_string(iostr, "\\n", 2);
+        continue;
+      } else if((flags =3D=3D 3) && c =3D=3D 0x0b) {
+        /* JSON has \f for formfeed */
+        raptor_iostream_write_counted_string(iostr, "\\f", 2);
+        continue;
+      } else if(c =3D=3D 0x0d) {
+        raptor_iostream_write_counted_string(iostr, "\\r", 2);
+        continue;
+      } else if(c < 0x20|| c =3D=3D 0x7f) {
+        raptor_iostream_write_counted_string(iostr, "\\u", 2);
+        raptor_iostream_format_hexadecimal(iostr, c, 4);
+        continue;
+      } else if(c < 0x80) {
+        raptor_iostream_write_byte(iostr, c);
+        continue;
+      }
     } else if(c < 0x80) {
+      /* Turtle long string has no escapes except delim */
       raptor_iostream_write_byte(iostr, c);
       continue;
-    }
+    } =

     =

     /* It is unicode */
     =

@@ -453,7 +461,7 @@
 =

     unichar_len=3Draptor_utf8_to_unicode_char(&unichar, string, len);
 =

-    if(flags =3D=3D 1 || flags =3D=3D 2) {
+    if(flags >=3D 1 && flags <=3D 3) {
       /* Turtle and JSON are UTF-8 - no need to escape */
       raptor_iostream_write_counted_string(iostr, string, len);
     } else {
@@ -511,15 +519,18 @@
   const unsigned char *quotes=3D(const unsigned char *)"\"\"\"\"";
   const unsigned char *q;
   size_t q_len;
+  int flags;
   =

   if(!s)
     return 1;
   =

-  q=3Draptor_turtle_writer_contains_newline(s) ? quotes : quotes+2;
+  /* Turtle """longstring""" (2) or "string" (1) */
+  flags=3Draptor_turtle_writer_contains_newline(s) ? 2 : 1;
+  q=3D(flags =3D=3D 2) ? quotes : quotes+2;
   q_len=3D(q =3D=3D quotes) ? 3 : 1;
   raptor_iostream_write_counted_string(turtle_writer->iostr, q, q_len);
   raptor_iostream_write_string_python(turtle_writer->iostr,
-                                      s, strlen((const char*)s), '"', 1);
+                                      s, strlen((const char*)s), '"', flag=
s);
   raptor_iostream_write_counted_string(turtle_writer->iostr, q, q_len);
 =

   return 0;


_______________________________________________
redland-commits mailing list
[email protected]
http://lists.librdf.org/mailman/listinfo/redland-commits

Reply via email to