Exemple #1
0
static void jx_pair_print( struct jx_pair *pair, buffer_t *b )
{
	if(!pair) return;

	jx_print_buffer(pair->key,b);
	buffer_putstring(b,":");
	jx_print_buffer(pair->value,b);
	if(pair->next) {
		buffer_putstring(b,",");
		jx_pair_print(pair->next,b);
	}
}
Exemple #2
0
void jx_comprehension_print(struct jx_comprehension *comp, buffer_t *b) {
	if (!comp) return;

	buffer_putstring(b, " for ");
	buffer_putstring(b, comp->variable);
	buffer_putstring(b, " in ");
	jx_print_buffer(comp->elements, b);
	if (comp->condition) {
		buffer_putstring(b, " if ");
		jx_print_buffer(comp->condition, b);
	}

	jx_comprehension_print(comp->next, b);
}
Exemple #3
0
void jx_print_stream( struct jx *j, FILE *file )
{
	buffer_t buffer;
	buffer_init(&buffer);
	jx_print_buffer(j,&buffer);
	fprintf(file,"%s",buffer_tostring(&buffer));
	buffer_free(&buffer);
}
Exemple #4
0
void jx_print_link( struct jx *j, struct link *l, time_t stoptime )
{
	buffer_t buffer;
	buffer_init(&buffer);
	jx_print_buffer(j,&buffer);
	link_write(l,buffer.buf,buffer.len,stoptime);
	buffer_free(&buffer);
}
Exemple #5
0
static void jx_item_print( struct jx_item *item, buffer_t *b )
{
	if(!item) return;

	jx_print_buffer(item->value,b);
	if(item->next) {
		buffer_putstring(b,",");
		jx_item_print(item->next,b);
	}
}
Exemple #6
0
char * jx_print_string( struct jx *j )
{
	buffer_t buffer;
	char *str;
	buffer_init(&buffer);
	jx_print_buffer(j,&buffer);
	buffer_dup(&buffer,&str);
	buffer_free(&buffer);
	return str;
}
Exemple #7
0
void jx_print_buffer( struct jx *j, buffer_t *b )
{
	if(!j) return;

	switch(j->type) {
		case JX_NULL:
			buffer_putstring(b,"null");
			break;
		case JX_DOUBLE:
			buffer_printf(b,"%g",j->u.double_value);
			break;
		case JX_BOOLEAN:
			buffer_printf(b,"%s",j->u.boolean_value ? "true" : "false");
			break;
		case JX_INTEGER:
			buffer_printf(b,"%lld",(long long)j->u.integer_value);
			break;
		case JX_SYMBOL:
			buffer_printf(b,"%s",j->u.symbol_name);
			break;
		case JX_STRING:
			jx_escape_string(j->u.string_value,b);
			break;
		case JX_ARRAY:
			buffer_putstring(b,"[");
			jx_item_print(j->u.items,b);
			buffer_putstring(b,"]");
			break;
		case JX_OBJECT:
			buffer_putstring(b,"{");
			jx_pair_print(j->u.pairs,b);
			buffer_putstring(b,"}");
			break;
		case JX_OPERATOR:
			jx_print_subexpr(j->u.oper.left,j->u.oper.type,b);
			buffer_putstring(b,jx_operator_string(j->u.oper.type));
			if (j->u.oper.type == JX_OP_CALL) {
				jx_item_print(j->u.oper.right->u.items, b);
				buffer_putstring(b, ")");
			} else {
				jx_print_subexpr(
					j->u.oper.right, j->u.oper.type, b);
			}
			if(j->u.oper.type==JX_OP_LOOKUP) buffer_putstring(b,"]");
			break;
		case JX_FUNCTION: buffer_putstring(b, j->u.func.name); break;
		case JX_ERROR:
			buffer_putstring(b, "error(");
			jx_print_buffer(j->u.err, b);
			buffer_putstring(b, ")");
			break;
	}
}
Exemple #8
0
void jx_print_link( struct jx *j, struct link *l, time_t stoptime )
{

	buffer_t buffer;
	buffer_init(&buffer);
	jx_print_buffer(j,&buffer);

	size_t len;
	const char *str = buffer_tolstring(&buffer, &len);

	link_write(l,str,len,stoptime);
	buffer_free(&buffer);
}
Exemple #9
0
void jx_print_subexpr( struct jx *j, jx_operator_t parent, buffer_t *b )
{
	if(!j) return;

	int do_parens = 0;

	if(j->type==JX_OPERATOR && jx_operator_precedence(parent) < jx_operator_precedence(j->u.oper.type)) {
		do_parens = 1;
	} else {
		do_parens = 0;
	}

	if(do_parens) buffer_putstring(b,"(");
	jx_print_buffer(j,b);
	if(do_parens) buffer_putstring(b,")");
}