From: MORIOKA Tomohiko Date: Sun, 14 Apr 2013 09:30:06 +0000 (+0900) Subject: (cos_read_string): New function. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=036d80c42369228dcc32bba9cea9088ed9bd33ef;p=chise%2Fconcord.git (cos_read_string): New function. --- diff --git a/read.c b/read.c index 79459ab..2fd1566 100644 --- 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; +}