16#define rb_intern_str(string) SYM2ID(rb_str_intern(string))
19#ifndef rb_obj_instance_variables
20#define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
23#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
27#define UNI_STRICT_CONVERSION 1
33#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
34#define UNI_MAX_BMP (UTF32)0x0000FFFF
35#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
36#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
37#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
39#define UNI_SUR_HIGH_START (UTF32)0xD800
40#define UNI_SUR_HIGH_END (UTF32)0xDBFF
41#define UNI_SUR_LOW_START (UTF32)0xDC00
42#define UNI_SUR_LOW_END (UTF32)0xDFFF
44static const int halfShift = 10;
46static const UTF32 halfBase = 0x0010000UL;
47static const UTF32 halfMask = 0x3FFUL;
49static unsigned char isLegalUTF8(
const UTF8 *source,
unsigned long length);
50static void unicode_escape(
char *
buf,
UTF16 character);
51static void unicode_escape_to_buffer(
FBuffer *buffer,
char buf[6],
UTF16 character);
52static void convert_UTF8_to_JSON_ASCII(
FBuffer *buffer,
VALUE string,
char escape_slash);
53static void convert_UTF8_to_JSON(
FBuffer *buffer,
VALUE string,
char escape_slash);
54static char *fstrndup(
const char *
ptr,
unsigned long len);
80#define GET_STATE_TO(self, state) \
81 TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
83#define GET_STATE(self) \
84 JSON_Generator_State *state; \
85 GET_STATE_TO(self, state)
87#define GENERATE_JSON(type) \
90 JSON_Generator_State *state; \
92 rb_scan_args(argc, argv, "01", &Vstate); \
93 Vstate = cState_from_state_s(cState, Vstate); \
94 TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
95 buffer = cState_prepare_buffer(Vstate); \
96 generate_json_##type(buffer, Vstate, state, self); \
97 return fbuffer_to_s(buffer)
101#ifdef RUBY_INTEGER_UNIFICATION
110static VALUE mString_to_json_raw_object(
VALUE self);
117static void State_free(
void *
state);
128#ifdef RUBY_INTEGER_UNIFICATION
158#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
159static inline void *ruby_zalloc(
size_t n)
166#ifdef TypedData_Make_Struct
168#define NEW_TYPEDDATA_WRAPPER 1
170#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
171#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
Our own, locale independent, character handling routines.
void * ruby_xmalloc(size_t size)
Allocates a storage instance.
struct JSON_Generator_StateStruct JSON_Generator_State
Internal header for Regexp.
Internal header for Math.
long buffer_initial_length