(cos_read_string): New function.
[chise/concord.git] / read.c
diff --git a/read.c b/read.c
index 79459ab..2fd1566 100644 (file)
--- a/read.c
+++ b/read.c
@@ -92,3 +92,30 @@ cos_read_char (unsigned char *str, size_t len, size_t start, size_t* endp)
 
   return -1;
 }
+
+COS_String
+cos_read_string (unsigned char *str, size_t len, size_t start, size_t* endp)
+{
+  size_t i = start;
+  int c;
+
+  if ( (len >= start + 2) && (str[i++] == '"') )
+    {
+      while ( ( i < len )
+             && ( (c = cos_read_utf8 (str, len, i, &i)) >= 0 )
+             )
+       {
+         if ( c == '"' )
+           {
+             return cos_make_string ((char*)&str[1], i - 2);
+           }
+         else if ( c == '\\' )
+           {
+             i++;
+             if ( cos_read_utf8 (str, len, i, &i) < 0 )
+               return NULL;
+           }
+       }
+    }
+  return NULL;
+}