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.1/json_number.c

#line 1 "json_number.rl"
// vim:syntax=ragel
#include 

#line 6 "json.cmod/json_number.c"
static const int JSON_number_start = 1;

static const int JSON_number_first_final = 8;

static const int JSON_number_error = 0;

#line 11 "json_number.rl"


p_wchar2 *_parse_JSON_number(p_wchar2 *p, p_wchar2 *pe) {
    p_wchar2 *i = p;
    int cs;
    int d = 0;
    double f;

    
#line 23 "json.cmod/json_number.c"
	{
	cs = JSON_number_start;
	}
#line 20 "json_number.rl"
    
#line 29 "json.cmod/json_number.c"
	{
	if ( p == pe )
		goto _out;
	switch ( cs )
	{
case 1:
	switch( (*p) ) {
		case 45: goto st2;
		case 46: goto tr2;
		case 48: goto st6;
	}
	if ( 49 <= (*p) && (*p) <= 57 )
		goto st7;
	goto st0;
st0:
	goto _out0;
st2:
	if ( ++p == pe )
		goto _out2;
case 2:
	switch( (*p) ) {
		case 46: goto tr2;
		case 48: goto st6;
	}
	if ( 49 <= (*p) && (*p) <= 57 )
		goto st7;
	goto st0;
tr2:
#line 10 "json_number.rl"
	{ d = 1; }
	goto st3;
st3:
	if ( ++p == pe )
		goto _out3;
case 3:
#line 65 "json.cmod/json_number.c"
	if ( 48 <= (*p) && (*p) <= 57 )
		goto st8;
	goto st0;
st8:
	if ( ++p == pe )
		goto _out8;
case 8:
#line 10 "json_number.rl"
	{ goto _out8; }
#line 75 "json.cmod/json_number.c"
	switch( (*p) ) {
		case 69: goto st4;
		case 101: goto st4;
	}
	if ( 48 <= (*p) && (*p) <= 57 )
		goto st8;
	goto st0;
st4:
	if ( ++p == pe )
		goto _out4;
case 4:
	switch( (*p) ) {
		case 43: goto st5;
		case 45: goto st5;
	}
	goto st0;
st5:
	if ( ++p == pe )
		goto _out5;
case 5:
	if ( 48 <= (*p) && (*p) <= 57 )
		goto st9;
	goto st0;
st9:
	if ( ++p == pe )
		goto _out9;
case 9:
#line 10 "json_number.rl"
	{ goto _out9; }
#line 105 "json.cmod/json_number.c"
	if ( 48 <= (*p) && (*p) <= 57 )
		goto st9;
	goto st0;
st6:
	if ( ++p == pe )
		goto _out6;
case 6:
	if ( (*p) == 46 )
		goto tr2;
	goto st0;
st7:
	if ( ++p == pe )
		goto _out7;
case 7:
	if ( (*p) == 46 )
		goto tr2;
	if ( 48 <= (*p) && (*p) <= 57 )
		goto st7;
	goto st0;
	}
	_out0: cs = 0; goto _out; 
	_out2: cs = 2; goto _out; 
	_out3: cs = 3; goto _out; 
	_out8: cs = 8; goto _out; 
	_out4: cs = 4; goto _out; 
	_out5: cs = 5; goto _out; 
	_out9: cs = 9; goto _out; 
	_out6: cs = 6; goto _out; 
	_out7: cs = 7; goto _out; 

	_out: {}
	}
#line 21 "json_number.rl"

    if (cs >= JSON_number_first_final) {
	
	ptrdiff_t len = (ptrdiff_t)(i - p); 

	char *temp = (char*)malloc(len+1);

	if (temp == NULL) {
	    Pike_error("Not enough memory while parsing a number from JSON!");
	}

	*(temp + len--) = '\0';
	
	do {
	    *(temp + len) = (char)(*(i + len));
	} while(len-- > 0);

	len = (ptrdiff_t)(i - p);

	if (d == 1) {
	    if (1 != sscanf(temp, "%lf", &f)) {
		Pike_error("Error parsing float (%.*s) in JSON.", MINIMUM(len, 10), temp);
	    }
	    push_float(f);
	} else {
	    if (1 != sscanf(temp, "%d", &d)) {
		Pike_error("Error parsing integer (%.*s) in JSON.", MINIMUM(len, 10), temp);
	    }
	    push_int(d);
	}
	return p;
    }

    Pike_error("Error parsing number at '%c' in JSON.\n", (char)*i);
    return NULL; // make gcc happy
}



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