static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) { yajl_parser_wrapper * wrapper; GetParser((VALUE)ctx, wrapper); VALUE keyStr; #ifdef HAVE_RUBY_ENCODING_H rb_encoding *default_internal_enc = rb_default_internal_encoding(); #endif if (wrapper->symbolizeKeys) { char buf[stringLen+1]; memcpy(buf, stringVal, stringLen); buf[stringLen] = 0; yajl_set_static_value(ctx, ID2SYM(rb_intern(buf))); } else { keyStr = rb_str_new((const char *)stringVal, stringLen); #ifdef HAVE_RUBY_ENCODING_H rb_enc_associate(keyStr, utf8Encoding); if (default_internal_enc) { keyStr = rb_str_export_to_enc(keyStr, default_internal_enc); } #endif yajl_set_static_value(ctx, keyStr); } yajl_check_and_fire_callback(ctx); return 1; }
static int yajl_found_number(void * ctx, const char * numberVal, unsigned int numberLen) { char buf[numberLen+1]; buf[numberLen] = 0; memcpy(buf, numberVal, numberLen); if (memchr(buf, '.', numberLen) || memchr(buf, 'e', numberLen) || memchr(buf, 'E', numberLen)) { yajl_set_static_value(ctx, rb_float_new(strtod(buf, NULL))); } else { yajl_set_static_value(ctx, rb_cstr2inum(buf, 10)); } return 1; }
static int yajl_found_start_array(void * ctx) { yajl_parser_wrapper * wrapper; GetParser((VALUE)ctx, wrapper); wrapper->nestedArrayLevel++; yajl_set_static_value(ctx, rb_ary_new()); return 1; }
static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) { VALUE str = rb_str_new((const char *)stringVal, stringLen); #ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(str, utf8Encoding); #endif yajl_set_static_value(ctx, str); yajl_check_and_fire_callback(ctx); return 1; }
static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) { VALUE str = rb_str_new((const char *)stringVal, stringLen); #ifdef HAVE_RUBY_ENCODING_H rb_encoding *default_internal_enc = rb_default_internal_encoding(); rb_enc_associate(str, utf8Encoding); if (default_internal_enc) { str = rb_str_export_to_enc(str, default_internal_enc); } #endif yajl_set_static_value(ctx, str); yajl_check_and_fire_callback(ctx); return 1; }
static int yajl_found_boolean(void * ctx, int boolean) { yajl_set_static_value(ctx, boolean ? Qtrue : Qfalse); yajl_check_and_fire_callback(ctx); return 1; }
/* YAJL Callbacks */ static int yajl_found_null(void * ctx) { yajl_set_static_value(ctx, Qnil); yajl_check_and_fire_callback(ctx); return 1; }