Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Parser.JSON2
Viewing contents of Public_Parser_JSON2-0.4/json_string.c

#line 1 "json_string.rl"
// vim:syntax=ragel
#define HEX2DEC(x) ((x) <= '9' ? (x) - '0' : ((x) < 'G') ? (x) - 'A' + 10 : (x) - 'a' + 10)


#line 7 "json.cmod/json_string.c"
static const int JSON_string_start = 1;

static const int JSON_string_first_final = 9;

static const int JSON_string_error = 0;

#line 67 "json_string.rl"


p_wchar2 *_parse_JSON_string(p_wchar2 *p, p_wchar2 *pe, struct parser_state *state) {
    p_wchar2 temp = 0;
    p_wchar2 *mark = 0;
    struct string_builder s;
    int cs;

    if (!state->validate)
	init_string_builder(&s, 1);

    
#line 27 "json.cmod/json_string.c"
	{
	cs = JSON_string_start;
	}
#line 79 "json_string.rl"
    
#line 33 "json.cmod/json_string.c"
	{
	if ( p == pe )
		goto _out;
	switch ( cs )
	{
case 1:
	if ( (*p) == 34 )
		goto st2;
	goto st0;
st0:
	goto _out0;
st2:
	if ( ++p == pe )
		goto _out2;
case 2:
	switch( (*p) ) {
		case 34: goto tr3;
		case 92: goto tr4;
	}
	goto tr2;
tr2:
#line 36 "json_string.rl"
	{
	mark = p;
    }
	goto st3;
tr8:
#line 24 "json_string.rl"
	{
	if (!state->validate) switch((*p)) {
        case '"':
        case '\\':      string_builder_putchar(&s, (*p)); break;
        case 'b':       string_builder_putchar(&s, '\b'); break;
        case 'f':       string_builder_putchar(&s, '\f'); break;
	case 'n':       string_builder_putchar(&s, '\n'); break;
        case 'r':       string_builder_putchar(&s, '\r'); break;
        case 't':       string_builder_putchar(&s, '\t'); break;
	}
    }
#line 40 "json_string.rl"
	{ mark = p + 1; }
	goto st3;
tr13:
#line 13 "json_string.rl"
	{
	if (!state->validate) {
	    temp *= 16;
	    temp += HEX2DEC((*p));
	}
    }
#line 20 "json_string.rl"
	{
	if (!state->validate) string_builder_putchar(&s, temp);
    }
#line 40 "json_string.rl"
	{ mark = p + 1; }
	goto st3;
st3:
	if ( ++p == pe )
		goto _out3;
case 3:
#line 95 "json.cmod/json_string.c"
	switch( (*p) ) {
		case 34: goto tr6;
		case 92: goto tr7;
	}
	goto st3;
tr3:
#line 36 "json_string.rl"
	{
	mark = p;
    }
#line 42 "json_string.rl"
	{
	if (p - mark > 0) {
            //string_builder_binary_strcat(s, mark, (ptrdiff_t)(fpc - mark));

	    // looking for the lowest possible magnitude here may be worth it. i am not entirely
	    // sure if i want to do the copying here.
	    if (!state->validate)
		string_builder_append(&s, MKPCHARP(mark, 2), (ptrdiff_t)(p - mark));
#ifdef DEBUG
	    //printf("parsed string: '%.*s'\n", (int)(fpc - mark), mark);
#endif
        }
    }
	goto st9;
tr6:
#line 42 "json_string.rl"
	{
	if (p - mark > 0) {
            //string_builder_binary_strcat(s, mark, (ptrdiff_t)(fpc - mark));

	    // looking for the lowest possible magnitude here may be worth it. i am not entirely
	    // sure if i want to do the copying here.
	    if (!state->validate)
		string_builder_append(&s, MKPCHARP(mark, 2), (ptrdiff_t)(p - mark));
#ifdef DEBUG
	    //printf("parsed string: '%.*s'\n", (int)(fpc - mark), mark);
#endif
        }
    }
	goto st9;
st9:
	if ( ++p == pe )
		goto _out9;
case 9:
#line 66 "json_string.rl"
	{ goto _out9; }
#line 143 "json.cmod/json_string.c"
	goto st0;
tr4:
#line 36 "json_string.rl"
	{
	mark = p;
    }
#line 42 "json_string.rl"
	{
	if (p - mark > 0) {
            //string_builder_binary_strcat(s, mark, (ptrdiff_t)(fpc - mark));

	    // looking for the lowest possible magnitude here may be worth it. i am not entirely
	    // sure if i want to do the copying here.
	    if (!state->validate)
		string_builder_append(&s, MKPCHARP(mark, 2), (ptrdiff_t)(p - mark));
#ifdef DEBUG
	    //printf("parsed string: '%.*s'\n", (int)(fpc - mark), mark);
#endif
        }
    }
	goto st4;
tr7:
#line 42 "json_string.rl"
	{
	if (p - mark > 0) {
            //string_builder_binary_strcat(s, mark, (ptrdiff_t)(fpc - mark));

	    // looking for the lowest possible magnitude here may be worth it. i am not entirely
	    // sure if i want to do the copying here.
	    if (!state->validate)
		string_builder_append(&s, MKPCHARP(mark, 2), (ptrdiff_t)(p - mark));
#ifdef DEBUG
	    //printf("parsed string: '%.*s'\n", (int)(fpc - mark), mark);
#endif
        }
    }
	goto st4;
st4:
	if ( ++p == pe )
		goto _out4;
case 4:
#line 185 "json.cmod/json_string.c"
	switch( (*p) ) {
		case 34: goto tr8;
		case 47: goto tr8;
		case 92: goto tr8;
		case 98: goto tr8;
		case 102: goto tr8;
		case 110: goto tr8;
		case 114: goto tr8;
		case 116: goto tr8;
		case 117: goto st5;
	}
	goto st0;
st5:
	if ( ++p == pe )
		goto _out5;
case 5:
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr10;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto tr10;
	} else
		goto tr10;
	goto st0;
tr10:
#line 9 "json_string.rl"
	{
	if (!state->validate) temp = HEX2DEC((*p));
    }
	goto st6;
st6:
	if ( ++p == pe )
		goto _out6;
case 6:
#line 221 "json.cmod/json_string.c"
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr11;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto tr11;
	} else
		goto tr11;
	goto st0;
tr11:
#line 13 "json_string.rl"
	{
	if (!state->validate) {
	    temp *= 16;
	    temp += HEX2DEC((*p));
	}
    }
	goto st7;
st7:
	if ( ++p == pe )
		goto _out7;
case 7:
#line 244 "json.cmod/json_string.c"
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr12;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto tr12;
	} else
		goto tr12;
	goto st0;
tr12:
#line 13 "json_string.rl"
	{
	if (!state->validate) {
	    temp *= 16;
	    temp += HEX2DEC((*p));
	}
    }
	goto st8;
st8:
	if ( ++p == pe )
		goto _out8;
case 8:
#line 267 "json.cmod/json_string.c"
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr13;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto tr13;
	} else
		goto tr13;
	goto st0;
	}
	_out0: cs = 0; goto _out; 
	_out2: cs = 2; goto _out; 
	_out3: cs = 3; goto _out; 
	_out9: cs = 9; goto _out; 
	_out4: cs = 4; goto _out; 
	_out5: cs = 5; goto _out; 
	_out6: cs = 6; goto _out; 
	_out7: cs = 7; goto _out; 
	_out8: cs = 8; goto _out; 

	_out: {}
	}
#line 80 "json_string.rl"

    if (cs < JSON_string_first_final) {
	if (!state->validate) {
	    free_string_builder(&s);
#ifdef JUMP
	    Pike_error("Failed to parse string at '%c'.\n", (char)*p);
#endif
	}

	push_int((int)p);
	return NULL;
    }

    if (!state->validate)
	push_string(finish_string_builder(&s));

    return p;
}

#undef HEX2DEC


gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University