示例#1
0
static inline int
enc_colon(Encoder* e)
{
    if(e->pretty)
        return enc_literal(e, " : ", 3);
    return enc_char(e, ':');
}
示例#2
0
static inline int
enc_end_object(Encoder* e)
{
    e->shiftcnt--;
    MAYBE_PRETTY(e);
    return enc_char(e, '}');
}
示例#3
0
static inline int
enc_end_array(Encoder* e)
{
    e->shiftcnt--;
    MAYBE_PRETTY(e);
    return enc_char(e, ']');
}
示例#4
0
static inline int
enc_comma(Encoder* e)
{
    if(!enc_char(e, ','))
        return 0;
    MAYBE_PRETTY(e);
    return 1;
}
示例#5
0
static inline int
enc_start_array(Encoder* e)
{
    e->count++;
    e->shiftcnt++;
    if(!enc_char(e, '['))
        return 0;
    MAYBE_PRETTY(e);
    return 1;
}
示例#6
0
文件: utf8.c 项目: benoitc/couchjs
static JSBool
enc_charbuf(const jschar* src, size_t srclen, char* dst, size_t* dstlenp)
{
    size_t i;
    size_t utf8Len;
    size_t dstlen = *dstlenp;
    size_t origDstlen = dstlen;
    jschar c;
    jschar c2;
    uint32 v;
    uint8 utf8buf[6];

    if(!dst)
    {
        dstlen = origDstlen = (size_t) -1;
    }

    while(srclen)
    {
        c = *src++;
        srclen--;

        if((c >= 0xDC00) && (c <= 0xDFFF)) goto bad_surrogate;

        if(c < 0xD800 || c > 0xDBFF)
        {
            v = c;
        }
        else
        {
            if(srclen < 1) goto buffer_too_small;
            c2 = *src++;
            srclen--;
            if ((c2 < 0xDC00) || (c2 > 0xDFFF))
            {
                c = c2;
                goto bad_surrogate;
            }
            v = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
        }
        if(v < 0x0080)
        {
            /* no encoding necessary - performance hack */
            if(!dstlen) goto buffer_too_small;
            if(dst) *dst++ = (char) v;
            utf8Len = 1;
        }
        else
        {
            utf8Len = enc_char(utf8buf, v);
            if(utf8Len > dstlen) goto buffer_too_small;
            if(dst)
            {
                for (i = 0; i < utf8Len; i++)
                {
                    *dst++ = (char) utf8buf[i];
                }
            }
        }
        dstlen -= utf8Len;
    }

    *dstlenp = (origDstlen - dstlen);
    return JS_TRUE;

bad_surrogate:
    *dstlenp = (origDstlen - dstlen);
    return JS_FALSE;

buffer_too_small:
    *dstlenp = (origDstlen - dstlen);
    return JS_FALSE;
}
示例#7
0
文件: encoder.c 项目: msassak/jiffy
static inline int
enc_colon(Encoder* e)
{
    return enc_char(e, ':');
}
示例#8
0
文件: encoder.c 项目: msassak/jiffy
static inline int
enc_comma(Encoder* e)
{
    return enc_char(e, ',');
}
示例#9
0
文件: encoder.c 项目: msassak/jiffy
static inline int
enc_end_array(Encoder* e)
{
    return enc_char(e, ']');
}
示例#10
0
文件: encoder.c 项目: msassak/jiffy
static inline int
enc_start_array(Encoder* e)
{
    e->count++;
    return enc_char(e, '[');
}
示例#11
0
文件: encoder.c 项目: msassak/jiffy
static inline int
enc_end_object(Encoder* e)
{
    return enc_char(e, '}');
}
示例#12
0
文件: encoder.c 项目: msassak/jiffy
static inline int
enc_start_object(Encoder* e)
{
    e->count++;
    return enc_char(e, '{');
}
示例#13
0
文件: utf8.c 项目: AvianFlu/couchdb
static JSBool
enc_charbuf(const jschar* src, size_t srclen, char* dst, size_t* dstlenp)
{
    size_t i;
    size_t utf8Len;
    size_t dstlen = *dstlenp;
    size_t origDstlen = dstlen;
    jschar c;
    jschar c2;
    uint32 v;
    uint8 utf8buf[6];

    if(!dst)
    {
        dstlen = origDstlen = (size_t) -1;
    }

    while(srclen)
    {
        c = *src++;
        srclen--;

        if(c <= 0xD7FF || c >= 0xE000)
        {
            v = (uint32) c;
        }
        else if(c >= 0xD800 && c <= 0xDBFF)
        {
            if(srclen < 1) goto buffer_too_small;
            c2 = *src++;
            srclen--;
            if(c2 >= 0xDC00 && c2 <= 0xDFFF)
            {
                v = (uint32) (((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000);
            }
            else
            {
                // Invalid second half of surrogate pair
                v = (uint32) 0xFFFD;
            }
        }
        else
        {
            // Invalid first half surrogate pair
            v = (uint32) 0xFFFD;
        }

        if(v < 0x0080)
        {
            /* no encoding necessary - performance hack */
            if(!dstlen) goto buffer_too_small;
            if(dst) *dst++ = (char) v;
            utf8Len = 1;
        }
        else
        {
            utf8Len = enc_char(utf8buf, v);
            if(utf8Len > dstlen) goto buffer_too_small;
            if(dst)
            {
                for (i = 0; i < utf8Len; i++)
                {
                    *dst++ = (char) utf8buf[i];
                }
            }
        }
        dstlen -= utf8Len;
    }
    
    *dstlenp = (origDstlen - dstlen);
    return JS_TRUE;

buffer_too_small:
    *dstlenp = (origDstlen - dstlen);
    return JS_FALSE;
}