Ruby
2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
ext
json
parser
parser.h
Go to the documentation of this file.
1
#ifndef _PARSER_H_
2
#define _PARSER_H_
3
4
#include "
ruby.h
"
5
6
#ifndef HAVE_RUBY_RE_H
7
#include "
re.h
"
8
#endif
9
10
#ifdef HAVE_RUBY_ST_H
11
#include "
ruby/st.h
"
12
#else
13
#include "
st.h
"
14
#endif
15
16
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
17
18
/* unicode */
19
20
typedef
unsigned
long
UTF32
;
/* at least 32 bits */
21
typedef
unsigned
short
UTF16
;
/* at least 16 bits */
22
typedef
unsigned
char
UTF8
;
/* typically 8 bits */
23
24
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
25
#define UNI_SUR_HIGH_START (UTF32)0xD800
26
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
27
#define UNI_SUR_LOW_START (UTF32)0xDC00
28
#define UNI_SUR_LOW_END (UTF32)0xDFFF
29
30
typedef
struct
JSON_ParserStruct
{
31
VALUE
Vsource
;
32
char
*
source
;
33
long
len
;
34
char
*
memo
;
35
VALUE
create_id
;
36
int
max_nesting
;
37
int
allow_nan
;
38
int
parsing_name
;
39
int
symbolize_names
;
40
VALUE
object_class
;
41
VALUE
array_class
;
42
VALUE
decimal_class
;
43
int
create_additions
;
44
VALUE
match_string
;
45
FBuffer
*
fbuffer
;
46
}
JSON_Parser
;
47
48
#define GET_PARSER \
49
GET_PARSER_INIT; \
50
if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
51
#define GET_PARSER_INIT \
52
JSON_Parser *json; \
53
TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
54
55
#define MinusInfinity "-Infinity"
56
#define EVIL 0x666
57
58
static
UTF32
unescape_unicode(
const
unsigned
char
*p);
59
static
int
convert_UTF32_to_UTF8(
char
*
buf
,
UTF32
ch);
60
static
char
*JSON_parse_object(
JSON_Parser
*json,
char
*p,
char
*pe,
VALUE
*result,
int
current_nesting);
61
static
char
*JSON_parse_value(
JSON_Parser
*json,
char
*p,
char
*pe,
VALUE
*result,
int
current_nesting);
62
static
char
*JSON_parse_integer(
JSON_Parser
*json,
char
*p,
char
*pe,
VALUE
*result);
63
static
char
*JSON_parse_float(
JSON_Parser
*json,
char
*p,
char
*pe,
VALUE
*result);
64
static
char
*JSON_parse_array(
JSON_Parser
*json,
char
*p,
char
*pe,
VALUE
*result,
int
current_nesting);
65
static
VALUE
json_string_unescape(
VALUE
result,
char
*
string
,
char
*stringEnd);
66
static
char
*JSON_parse_string(
JSON_Parser
*json,
char
*p,
char
*pe,
VALUE
*result);
67
static
VALUE
convert_encoding(
VALUE
source);
68
static
VALUE
cParser_initialize(
int
argc
,
VALUE
*
argv
,
VALUE
self
);
69
static
VALUE
cParser_parse(
VALUE
self
);
70
static
void
JSON_mark(
void
*json);
71
static
void
JSON_free(
void
*json);
72
static
VALUE
cJSON_parser_s_allocate(
VALUE
klass
);
73
static
VALUE
cParser_source(
VALUE
self
);
74
#ifndef ZALLOC
75
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
76
static
inline
void
*ruby_zalloc(
size_t
n
)
77
{
78
void
*p =
ruby_xmalloc
(
n
);
79
memset
(p, 0,
n
);
80
return
p;
81
}
82
#endif
83
#ifdef TypedData_Make_Struct
84
static
const
rb_data_type_t
JSON_Parser_type;
85
#define NEW_TYPEDDATA_WRAPPER 1
86
#else
87
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, JSON_free, json)
88
#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
89
#endif
90
91
#endif
memset
void * memset(void *, int, size_t)
UTF32
unsigned long UTF32
Definition:
parser.h:20
JSON_ParserStruct::memo
char * memo
Definition:
parser.h:34
JSON_ParserStruct::max_nesting
int max_nesting
Definition:
parser.h:36
JSON_ParserStruct::len
long len
Definition:
parser.h:33
ruby_xmalloc
void * ruby_xmalloc(size_t size)
Definition:
gc.c:11978
re.h
JSON_ParserStruct::create_id
VALUE create_id
Definition:
parser.h:35
VALUE
unsigned long VALUE
Definition:
ruby.h:102
JSON_Parser
struct JSON_ParserStruct JSON_Parser
JSON_ParserStruct::create_additions
int create_additions
Definition:
parser.h:43
UTF16
unsigned short UTF16
Definition:
parser.h:21
UTF8
unsigned char UTF8
Definition:
parser.h:22
st.h
klass
VALUE klass
Definition:
rb_mjit_min_header-2.7.2.h:13302
JSON_ParserStruct::decimal_class
VALUE decimal_class
Definition:
parser.h:42
JSON_ParserStruct::match_string
VALUE match_string
Definition:
parser.h:44
ruby.h
JSON_ParserStruct::fbuffer
FBuffer * fbuffer
Definition:
parser.h:45
JSON_ParserStruct::allow_nan
int allow_nan
Definition:
parser.h:37
JSON_ParserStruct::parsing_name
int parsing_name
Definition:
parser.h:38
buf
unsigned char buf[MIME_BUF_SIZE]
Definition:
nkf.c:4322
JSON_ParserStruct::Vsource
VALUE Vsource
Definition:
parser.h:31
argv
char ** argv
Definition:
ruby.c:223
UTF32
unsigned long UTF32
Definition:
generator.h:29
argc
int argc
Definition:
ruby.c:222
FBufferStruct
Definition:
fbuffer.h:46
rb_data_type_struct
Definition:
ruby.h:1148
JSON_ParserStruct::array_class
VALUE array_class
Definition:
parser.h:41
JSON_ParserStruct::object_class
VALUE object_class
Definition:
parser.h:40
JSON_ParserStruct
Definition:
parser.h:30
JSON_ParserStruct::symbolize_names
int symbolize_names
Definition:
parser.h:39
n
const char size_t n
Definition:
rb_mjit_min_header-2.7.2.h:5491
JSON_ParserStruct::source
char * source
Definition:
parser.h:32
Generated by
1.8.19