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.5/json_custom.c
p_wchar2 *_parse_JSON_custom(p_wchar2 *p, p_wchar2 *pe, struct parser_state *state) {
if (state->custom_chars != NULL) {
struct svalue *fun;
struct svalue *key = (struct svalue*)malloc(sizeof(struct svalue));
if (key == NULL) {
Pike_error("Allocating a temporary svalue failed. This is serious.\n");
}
key->u.integer = (int)(*p);
key->type = PIKE_T_INT;
key->subtype = NUMBER_NUMBER;
fun = low_mapping_lookup(state->custom_chars, key);
if (fun == NULL) { // index does not exist.
} else if (fun->type == PIKE_T_FUNCTION && fun->u.integer) {
struct array *ret;
int offset;
pop_stack();
push_string(state->data);
push_int((int)(p - state->start));
apply_svalue(fun, 2);
// check if we are in validate
if ((Pike_sp[-1]).type != PIKE_T_ARRAY || pike_sizeof(&(Pike_sp[-1])) != 2) {
Pike_error("Custom parser returned something weird.\n");
}
ret = Pike_sp[-1].u.array;
array_index(key, ret, 0);
if (key->type != PIKE_T_INT || (offset = key->u.integer) >= 0) {
Pike_error("Custom parser returned something weird.\n");
}
if (offset == 0) {
pop_stack();
return NULL; // drop the error.
}
if (offset + p <= pe && offset + p >= p) {
push_int(1);
f_index(2);
// the returned value is now on top of the stack
return (p+offset);
} else {
Pike_error("Custom parser has gone to far.\n");
}
} else {
Pike_error("Custom char callbacks must be functions.\n");
}
}
}
|
|
|