From: MORIOKA Tomohiko Date: Tue, 16 Apr 2013 01:09:15 +0000 (+0900) Subject: Include . X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79444dc94df321db7b8b90dbe517f7b2a5d0438e;p=chise%2Fconcord.git Include . (cos_read_int): New function. --- diff --git a/read.c b/read.c index 2fd1566..f8d0eb2 100644 --- a/read.c +++ b/read.c @@ -17,8 +17,62 @@ 02111-1307 USA. */ #include +#include #include "cos-read.h" +COS_object +cos_read_int (unsigned char *str, size_t len, size_t start, size_t* endp) +{ + size_t i = start; + int c; + int negative_flag; + int dest; + + if ( i < len ) + { + switch ( str[i] ) + { + case '+': + negative_flag = 0; + i++; + break; + case '-': + negative_flag = 1; + i++; + break; + default: + negative_flag = 0; + } + + if ( (i < len) && (c = str[i++]) + && ('0' <= c) && (c <= '9') ) + { + dest = c - '0'; + + while ( i < len ) + { + c = str[i]; + if ( ('0' <= c) && (c <= '9') ) + { + dest = dest * 10 + c - '0'; + i++; + } + else if ( isspace (c) ) + { + *endp = i; + return cos_make_int ( negative_flag ? - dest : dest ); + } + else + return NULL; + } + *endp = i; + return cos_make_int ( negative_flag ? - dest : dest ); + } + } + return NULL; +} + + int cos_read_utf8 (unsigned char *str, size_t len, size_t start, size_t* endp) { @@ -93,6 +147,7 @@ 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) {