3 #ifdef HAVE_RUBY_ENCODING_H
4 static VALUE CEncoding_UTF_8;
5 static ID i_encoding, i_encode;
9 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
10 # define RB_OBJ_STRING(obj) (obj)
12 # define PRIsVALUE "s"
13 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
14 # define RB_OBJ_STRING(obj) StringValueCStr(obj)
58 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
59 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
60 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
61 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
62 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
63 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
64 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
65 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
74 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
93 case 4:
if ((a = (*--srcptr)) < 0x80 || a > 0xBF)
return 0;
94 case 3:
if ((a = (*--srcptr)) < 0x80 || a > 0xBF)
return 0;
95 case 2:
if ((a = (*--srcptr)) > 0xBF)
return 0;
99 case 0xE0:
if (a < 0xA0)
return 0;
break;
100 case 0xED:
if (a > 0x9F)
return 0;
break;
101 case 0xF0:
if (a < 0x90)
return 0;
break;
102 case 0xF4:
if (a > 0x8F)
return 0;
break;
103 default:
if (a < 0x80)
return 0;
106 case 1:
if (*source >= 0x80 && *source < 0xC2)
return 0;
108 if (*source > 0xF4)
return 0;
115 const char *digits =
"0123456789abcdef";
117 buf[2] = digits[character >> 12];
118 buf[3] = digits[(character >> 8) & 0xf];
119 buf[4] = digits[(character >> 4) & 0xf];
120 buf[5] = digits[character & 0xf];
138 char buf[6] = {
'\\',
'u' };
140 while (source < sourceEnd) {
143 if (source + extraBytesToRead >= sourceEnd) {
145 "partial character in source, but hit end");
149 "source sequence is illegal/malformed utf-8");
154 switch (extraBytesToRead) {
155 case 5: ch += *source++; ch <<= 6;
156 case 4: ch += *source++; ch <<= 6;
157 case 3: ch += *source++; ch <<= 6;
158 case 2: ch += *source++; ch <<= 6;
159 case 1: ch += *source++; ch <<= 6;
160 case 0: ch += *source++;
167 #if UNI_STRICT_CONVERSION
168 source -= (extraBytesToRead+1);
170 "source sequence is illegal/malformed utf-8");
176 if (ch >= 0x20 && ch <= 0x7f) {
212 #if UNI_STRICT_CONVERSION
213 source -= (extraBytesToRead+1);
215 "source sequence is illegal/malformed utf8");
236 const char *escape =
NULL;
239 char buf[6] = {
'\\',
'u' };
243 c = (
unsigned char) *
p;
298 if (len <= 0)
return NULL;
300 memccpy(result, ptr, 0, len);
317 assert(initial_length > 0);
337 unsigned long required;
344 for (required = fb->
capa; requested > required - fb->
len; required <<= 1);
346 if (required > fb->
capa) {
374 *(fb->
ptr + fb->
len) = newchr;
382 while (end > start) {
389 static char digits[] =
"0123456789";
393 if (sign < 0) number = -number;
394 do *tmp++ = digits[number % 10];
while (number /= 10);
395 if (sign < 0) *tmp++ =
'-';
403 unsigned long len =
fltoa(number, buf);
409 unsigned long len = fb->
len;
685 state->max_nesting = 19;
688 if (
RTEST(max_nesting)) {
692 state->max_nesting = 0;
757 char *indent = state->
indent;
767 if (max_nesting != 0 && depth > max_nesting) {
779 for (j = 0; j <
depth; j++) {
790 depth = --state->
depth;
794 for (j = 0; j <
depth; j++) {
806 char *indent = state->
indent;
813 if (max_nesting != 0 && depth > max_nesting) {
822 for (j = 0; j <
depth; j++) {
832 for (j = 0; j <
depth; j++) {
843 #ifdef HAVE_RUBY_ENCODING_H
844 obj =
rb_funcall(obj, i_encode, 1, CEncoding_UTF_8);
889 }
else if (
isnan(value)) {
907 }
else if (obj ==
Qnil) {
909 }
else if (obj ==
Qfalse) {
911 }
else if (obj ==
Qtrue) {
935 if (
state->object_delim) {
941 if (
state->object_delim2) {
949 if (
state->array_delim) {
987 if (!
state->quirks_mode) {
988 args[0] =
rb_str_new2(
"\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z");
1020 state->max_nesting = 19;
1036 if (obj == orig)
return obj;
1097 if (
state->indent) {
1100 state->indent_len = 0;
1138 state->space_len = 0;
1171 if (
state->space_before) {
1174 state->space_before_len = 0;
1209 if (
state->object_nl) {
1244 if (
state->array_nl) {
1462 #ifdef HAVE_RUBY_ENCODING_H
RUBY_EXTERN VALUE rb_cString
#define RSTRING_LEN(string)
static void fbuffer_free(FBuffer *fb)
static VALUE fbuffer_to_s(FBuffer *fb)
static VALUE eGeneratorError
static JSON_Generator_State * State_allocate()
VALUE rb_ary_entry(VALUE ary, long offset)
RUBY_EXTERN VALUE rb_cFloat
static VALUE i_SAFE_STATE_PROTOTYPE
static VALUE cState_array_nl(VALUE self)
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static VALUE CRegexp_MULTILINE
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self)
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character)
static FBuffer * fbuffer_alloc()
static const char trailingBytesForUTF8[256]
#define Data_Get_Struct(obj, type, sval)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self)
static VALUE cState_from_state_s(VALUE self, VALUE opts)
static void fbuffer_append_long(FBuffer *fb, long number)
static VALUE cState_array_nl_set(VALUE self, VALUE array_nl)
rb_hash_aset(CALLBACK_TABLE, id_num, cmd)
#define RFLOAT_VALUE(val)
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length)
#define option_given_p(opts, key)
static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static VALUE mString_Extend_json_create(VALUE self, VALUE o)
static const UTF32 offsetsFromUTF8[6]
static VALUE cState_object_nl(VALUE self)
static VALUE cState_check_circular_p(VALUE self)
static VALUE cState_max_nesting(VALUE self)
static void fbuffer_clear(FBuffer *fb)
static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
static VALUE cState_space_before_set(VALUE self, VALUE space_before)
static const UTF32 halfBase
static VALUE mGeneratorMethods
static VALUE cState_configure(VALUE self, VALUE opts)
#define RSTRING_PTR(string)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE cState_quirks_mode_p(VALUE self)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static void freverse(char *start, char *end)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
static void fbuffer_append_char(FBuffer *fb, char newchr)
static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
#define RARRAY_LEN(ARRAY)
#define RB_OBJ_STRING(obj)
static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self)
static VALUE cState_s_allocate(VALUE klass)
static VALUE cState_allow_nan_p(VALUE self)
static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self)
VALUE rb_path2class(const char *)
static VALUE cState_indent(VALUE self)
static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static VALUE cState_space_set(VALUE self, VALUE space)
static FBuffer * fbuffer_dup(FBuffer *fb)
static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len)
static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self)
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self)
#define MEMZERO(p, type, n)
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
VALUE rb_require(const char *)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
return Data_Wrap_Struct(CLASS_OF(interp), 0, ip_free, slave)
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static VALUE cState_generate(VALUE self, VALUE obj)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
VALUE rb_class_name(VALUE)
unsigned long initial_length
RUBY_EXTERN VALUE rb_cObject
static VALUE cState_depth(VALUE self)
static VALUE cState_indent_set(VALUE self, VALUE indent)
static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self)
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
static VALUE cState_depth_set(VALUE self, VALUE depth)
#define MEMCPY(p1, p2, type, n)
unsigned char buf[MIME_BUF_SIZE]
RUBY_EXTERN int isinf(double)
static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
VALUE rb_const_get(VALUE, ID)
static VALUE mString_to_json_raw_object(VALUE self)
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
RUBY_EXTERN VALUE rb_cRegexp
static const int halfShift
#define REALLOC_N(var, type, n)
static char * fstrndup(const char *ptr, unsigned long len)
#define RB_GC_GUARD(object)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE cState_to_h(VALUE self)
static VALUE cState_space_before(VALUE self)
static VALUE cState_partial_generate(VALUE self, VALUE obj)
static const UTF32 halfMask
static VALUE cState_ascii_only_p(VALUE self)
static void unicode_escape(char *buf, UTF16 character)
register unsigned int len
#define UNI_SUR_HIGH_START
static void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self)
int rb_respond_to(VALUE, ID)
VALUE rb_define_module_under(VALUE outer, const char *name)
static VALUE CJSON_SAFE_STATE_PROTOTYPE
static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static FBuffer * cState_prepare_buffer(VALUE self)
static VALUE cState_aref(VALUE self, VALUE name)
static VALUE cState_quirks_mode_set(VALUE self, VALUE enable)
static void fbuffer_append_str(FBuffer *fb, VALUE str)
static VALUE mString_Extend
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
#define GENERATE_JSON(type)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static VALUE cState_object_nl_set(VALUE self, VALUE object_nl)
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
#define UNI_SUR_LOW_START
static VALUE eNestingError
#define UNI_REPLACEMENT_CHAR
#define assert(condition)
return rb_funcall(q->proc, ID_call, 0)
#define StringValuePtr(v)
static VALUE cState_init_copy(VALUE obj, VALUE orig)
static VALUE cState_space(VALUE self)
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self)
#define FBUFFER_INITIAL_LENGTH
VALUE rb_define_module(const char *name)
static long fltoa(long number, char *buf)
static FBuffer * fbuffer_alloc_with_length(unsigned long initial_length)
RUBY_EXTERN VALUE rb_cFixnum
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new2(const char *)
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
static VALUE mString_included_s(VALUE self, VALUE modul)
VALUE rb_str_new(const char *, long)
VALUE rb_obj_class(VALUE)
static void State_free(JSON_Generator_State *state)