3 #ifdef HAVE_RUBY_ENCODING_H
4 static VALUE CEncoding_UTF_8;
5 static ID i_encoding, i_encode;
49 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,
50 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,
51 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,
52 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,
53 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,
54 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,
55 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,
56 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
65 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
80 const UTF8 *srcptr = source+length;
84 case 4:
if ((a = (*--srcptr)) < 0x80 || a > 0xBF)
return 0;
85 case 3:
if ((a = (*--srcptr)) < 0x80 || a > 0xBF)
return 0;
86 case 2:
if ((a = (*--srcptr)) > 0xBF)
return 0;
90 case 0xE0:
if (a < 0xA0)
return 0;
break;
91 case 0xED:
if (a > 0x9F)
return 0;
break;
92 case 0xF0:
if (a < 0x90)
return 0;
break;
93 case 0xF4:
if (a > 0x8F)
return 0;
break;
94 default:
if (a < 0x80)
return 0;
97 case 1:
if (*source >= 0x80 && *source < 0xC2)
return 0;
99 if (*source > 0xF4)
return 0;
106 const char *digits =
"0123456789abcdef";
108 buf[2] = digits[character >> 12];
109 buf[3] = digits[(character >> 8) & 0xf];
110 buf[4] = digits[(character >> 4) & 0xf];
111 buf[5] = digits[character & 0xf];
129 char buf[6] = {
'\\',
'u' };
131 while (source < sourceEnd) {
134 if (source + extraBytesToRead >= sourceEnd) {
136 "partial character in source, but hit end");
140 "source sequence is illegal/malformed utf-8");
145 switch (extraBytesToRead) {
146 case 5: ch += *source++; ch <<= 6;
147 case 4: ch += *source++; ch <<= 6;
148 case 3: ch += *source++; ch <<= 6;
149 case 2: ch += *source++; ch <<= 6;
150 case 1: ch += *source++; ch <<= 6;
151 case 0: ch += *source++;
158 #if UNI_STRICT_CONVERSION
159 source -= (extraBytesToRead+1);
161 "source sequence is illegal/malformed utf-8");
167 if (ch >= 0x20 && ch <= 0x7f) {
203 #if UNI_STRICT_CONVERSION
204 source -= (extraBytesToRead+1);
206 "source sequence is illegal/malformed utf8");
227 const char *escape =
NULL;
230 char buf[6] = {
'\\',
'u' };
232 for (start = 0, end = 0; end <
len;) {
234 c = (
unsigned char) *
p;
289 if (len <= 0)
return NULL;
291 memccpy(result, ptr, 0, len);
300 memset((
void *) fb, 0,
sizeof(
FBuffer));
308 assert(initial_length > 0);
310 memset((
void *) fb, 0,
sizeof(
FBuffer));
328 unsigned long required;
335 for (required = fb->
capa; requested > required - fb->
len; required <<= 1);
337 if (required > fb->
capa) {
365 *(fb->
ptr + fb->
len) = newchr;
373 while (end > start) {
374 c = *end, *end-- = *start, *start++ = c;
380 static char digits[] =
"0123456789";
384 if (sign < 0) number = -number;
385 do *tmp++ = digits[number % 10];
while (number /= 10);
386 if (sign < 0) *tmp++ =
'-';
394 unsigned long len =
fltoa(number, buf);
400 unsigned long len = fb->
len;
676 state->max_nesting = 19;
679 if (
RTEST(max_nesting)) {
683 state->max_nesting = 0;
748 char *indent = state->
indent;
755 long depth = ++state->
depth;
758 if (max_nesting != 0 && depth > max_nesting) {
770 for (j = 0; j < depth; j++) {
781 depth = --state->
depth;
785 for (j = 0; j < depth; j++) {
797 char *indent = state->
indent;
802 long depth = ++state->
depth;
804 if (max_nesting != 0 && depth > max_nesting) {
813 for (j = 0; j < depth; j++) {
819 state->
depth = --depth;
823 for (j = 0; j < depth; j++) {
834 #ifdef HAVE_RUBY_ENCODING_H
835 obj =
rb_funcall(obj, i_encode, 1, CEncoding_UTF_8);
880 }
else if (
isnan(value)) {
898 }
else if (obj ==
Qnil) {
900 }
else if (obj ==
Qfalse) {
902 }
else if (obj ==
Qtrue) {
926 if (
state->object_delim) {
932 if (
state->object_delim2) {
940 if (
state->array_delim) {
978 if (!
state->quirks_mode) {
979 args[0] =
rb_str_new2(
"\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z");
1011 state->max_nesting = 19;
1087 if (
state->indent) {
1090 state->indent_len = 0;
1128 state->space_len = 0;
1161 if (
state->space_before) {
1164 state->space_before_len = 0;
1199 if (
state->object_nl) {
1234 if (
state->array_nl) {
1452 #ifdef HAVE_RUBY_ENCODING_H