src/mongoose/mongoose.cpp
static size_t parse_chunk(char *buf, size_t len, char **chunk_data,
                          size_t *chunk_len) {
    unsigned char *s = (unsigned char *) buf;
    size_t n = 0; /* scanned chunk length */
    size_t i = 0; /* index in s */

    /* Scan chunk length. That should be a hexadecimal number. */
    while (i < len && isxdigit(s[i])) {
        n *= 16;
        n += (s[i] >= '0' && s[i] <= '9') ? s[i] - '0' : tolower(s[i]) - 'a' + 10;
        i++;
    }

    /* Skip new line */
    if (i == 0 || i + 2 > len || s[i] != '\r' || s[i + 1] != '\n') {
        return 0;
    }
    i += 2;

    /* Record where the data is */
    *chunk_data = (char *) s + i;
    *chunk_len = n;

    /* Skip data */
    i += n;

    /* Skip new line */
    if (i == 0 || i + 2 > len || s[i] != '\r' || s[i + 1] != '\n') {
        return 0;
    }
    return i + 2;
}
/*
 * Parse chunked-encoded buffer. Return 0 if the buffer is not encoded, or
 * if it's incomplete. If the chunk is fully buffered, return total number of
 * bytes in a chunk, and store data in `data`, `data_len`.
 */
Parse chunked-encoded buffer. Return 0 if the buffer is not encoded, or
if it's incomplete. If the chunk is fully buffered, return total number of
bytes in a chunk, and store data in `data`, `data_len`.
Parse chunked - encoded buffer . Return 0 if the buffer is not encoded or if it ' s incomplete . If the chunk is fully buffered return total number of bytes in a chunk and store data in ` data ` ` data_len ` .
static size_t parse_chunk(char *buf, size_t len, char **chunk_data,
                          size_t *chunk_len) {
    unsigned char *s = (unsigned char *) buf;
    size_t n = 0; 
    size_t i = 0; 
    while (i < len && isxdigit(s[i])) {
        n *= 16;
        n += (s[i] >= '0' && s[i] <= '9') ? s[i] - '0' : tolower(s[i]) - 'a' + 10;
        i++;
    }
    if (i == 0 || i + 2 > len || s[i] != '\r' || s[i + 1] != '\n') {
        return 0;
    }
    i += 2;
    *chunk_data = (char *) s + i;
    *chunk_len = n;
    i += n;
    if (i == 0 || i + 2 > len || s[i] != '\r' || s[i + 1] != '\n') {
        return 0;
    }
    return i + 2;
}
static size_t parse_chunk ( char * buf , size_t len , char * * chunk_data , size_t * chunk_len ) { unsigned char * s = ( unsigned char * ) buf ; size_t n = 0 ; size_t i = 0 ; while ( i < len && isxdigit ( s [ i ] ) ) { n *= 16 ; n += ( s [ i ] >= ' ' && s [ i ] <= ' ' ) ? s [ i ] - ' ' : tolower ( s [ i ] ) - ' ' + 10 ; i ++ ; } if ( i == 0 || i + 2 > len || s [ i ] != ' \r ' || s [ i + 1 ] != ' \n ' ) { return 0 ; } i += 2 ; * chunk_data = ( char * ) s + i ; * chunk_len = n ; i += n ; if ( i == 0 || i + 2 > len || s [ i ] != ' \r ' || s [ i + 1 ] != ' \n ' ) { return 0 ; } return i + 2 ; }
Parse chunked-encoded buffer.
Parse chunked - encoded buffer .
/* scanned chunk length */ /* index in s */ /* Scan chunk length. That should be a hexadecimal number. */ /* Skip new line */ /* Record where the data is */ /* Skip data */ /* Skip new line */