(cos_read_string): New function.
authorMORIOKA Tomohiko <tomo.git@chise.org>
Sun, 14 Apr 2013 09:30:06 +0000 (18:30 +0900)
committerMORIOKA Tomohiko <tomo.git@chise.org>
Sun, 14 Apr 2013 09:30:06 +0000 (18:30 +0900)
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;
+}