Ejemplo n.º 1
0
const char *
orderly_get_error_context(orderly_reader r,
                          const char * schema, unsigned int len)
{

    unsigned int offset = r->finalOffset;
    const char * arrow = "                     (right here) ------^\n";    

    r->errBuf = orderly_buf_alloc(&(r->alloc));

    /* now we append as many spaces as needed to make sure the error
     * falls at char 41, if verbose was specified */
    {
        unsigned int start, end, i;
        unsigned int spacesNeeded;

        spacesNeeded = (offset < 30 ? 40 - offset : 10);
        start = (offset >= 30 ? offset - 30 : 0);
        end = (offset + 30 > len ? len: offset + 30);
    
        for (i=0;i<spacesNeeded;i++) {
            orderly_buf_append_string(r->errBuf, " ");
        }
        
        for (;start < end;start++, i++) {
            if (schema[start] != '\n' && schema[start] != '\r')
            {
                orderly_buf_append(r->errBuf, schema + start, 1);
            }
            else
            {
                orderly_buf_append_string(r->errBuf, " ");
            }
        }
        assert(i <= 71);
        orderly_buf_append_string(r->errBuf, "\n");
        orderly_buf_append_string(r->errBuf, arrow);
    }

    return (const char *) orderly_buf_data(r->errBuf);
}
Ejemplo n.º 2
0
static void
bufAppendCallback(void * ctx, const char * str, unsigned int len)
{
    orderly_buf_append((orderly_buf) ctx, str, len);
}