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

File Contents

Contents of /Public_Parser_JSON2-0.8/json.h:

#define PUSH_SPECIAL(X) do {if (!state->validate) {			\
    push_text("Public.Parser.JSON2." X); 				\
    APPLY_MASTER("resolv", 1);						\
    if (((struct svalue*)(Pike_sp - 1))->type != PIKE_T_OBJECT) { 	\
	Pike_error("Could not resolv program '%s'\n.", 			\
		   "Public.Parser.JSON2." X );  			\
    } 									\
} } while(0)

#define PARSE(X, FPC) do {						\
    state->level++;							\
    i = _parse_JSON_##X(FPC, pe, state);				\
    state->level--;							\
    if (i == NULL) {							\
	return NULL;							\
    }									\
    c++;								\
    } while(0)								

#define JSON_CONVERT(a,b) do {						\
    switch (a->size_shift) {						\
    case 0:								\
	b=(p_wchar2 *)malloc(sizeof(p_wchar2) * a->len);		\
	if (b == NULL) {						\
	    SIMPLE_OUT_OF_MEMORY_ERROR (state.validate == 1 ? "validate" : "parse", sizeof(p_wchar2) * a->len); \
	}								\
        convert_0_to_2(b,STR0(a), a->len);				\
	break;								\
    case 1:								\
	b=(p_wchar2 *)malloc(sizeof(p_wchar2) * a->len);		\
	if (b == NULL) {						\
	    SIMPLE_OUT_OF_MEMORY_ERROR (state.validate == 1 ? "validate" : "parse", sizeof(p_wchar2) * a->len); \
	}								\
        convert_1_to_2(b,STR1(a), a->len);				\
	break;								\
    case 2:								\
	b = STR2(a);							\
	break;								\
    default:								\
	Pike_error("Bad string shift.\n");				\
	break;								\
    } } while (0)

#define IS_NUNICODE(x)	(((x) < 0 || (x) > 0xd7ff) && ((x) < 0xe000 || (x) > 0x10ffff))

#define CHECK_UNICODE(x) do {					\
    switch ((x)->size_shift) {						\
    case 0:								\
	break;								\
    case 1: {								\
	p_wchar1 *s = STR1((x));					\
	p_wchar1 *se = s + (x)->len;					\
									\
	for (;s < se; s++) 						\
	    if (IS_NUNICODE(*s)) {					\
		push_constant_text("A string contains a non-unicode char.\n");	\
		return 0;							\
	    }								\
	break;	}							\
    case 2: {							\
	p_wchar2 *s = STR1((x));					\
	p_wchar2 *se = s + (x)->len;					\
									\
	for (;s < se; s++) 						\
	    if (IS_NUNICODE(*s)) {					\
		push_constant_text("A string contains a non-unicode char.\n");	\
		return 0;							\
	    }								\
	break;}								\
    default:								\
	Pike_error("Bad string shift.\n");				\
	break;								\
    }} while (0)

struct parser_state {
    unsigned int level;
    short validate;
#ifdef JSON_CUSTOM_TYPES
    struct mapping *custom_chars;
#endif
    struct pike_string *data;
};

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