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 };
89 const UTF8 *srcptr = source+length;
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' };
241 for (start = 0, end = 0; end <
len;) {
243 c = (
unsigned char) *
p;
298 if (len <= 0)
return NULL;
300 memccpy(result, ptr, 0, len);
309 memset((
void *) fb, 0,
sizeof(
FBuffer));
317 assert(initial_length > 0);
319 memset((
void *) fb, 0,
sizeof(
FBuffer));
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) {
383 c = *end, *end-- = *start, *start++ = c;
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;
764 long depth = ++state->
depth;
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;
811 long depth = ++state->
depth;
813 if (max_nesting != 0 && depth > max_nesting) {
822 for (j = 0; j < depth; j++) {
828 state->
depth = --depth;
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