json 1.0.0 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +503 -0
  3. data/LICENSE +56 -0
  4. data/README.md +416 -0
  5. data/ext/json/ext/fbuffer/fbuffer.h +187 -0
  6. data/ext/json/ext/generator/depend +1 -0
  7. data/ext/json/ext/generator/extconf.rb +2 -7
  8. data/ext/json/ext/generator/generator.c +1312 -338
  9. data/ext/json/ext/generator/generator.h +177 -0
  10. data/ext/json/ext/parser/depend +1 -0
  11. data/ext/json/ext/parser/extconf.rb +28 -5
  12. data/ext/json/ext/parser/parser.c +1349 -689
  13. data/ext/json/ext/parser/parser.h +96 -0
  14. data/ext/json/ext/parser/parser.rl +644 -188
  15. data/ext/json/extconf.rb +3 -0
  16. data/json.gemspec +68 -0
  17. data/lib/json/add/bigdecimal.rb +58 -0
  18. data/lib/json/add/complex.rb +51 -0
  19. data/lib/json/add/core.rb +12 -0
  20. data/lib/json/add/date.rb +54 -0
  21. data/lib/json/add/date_time.rb +67 -0
  22. data/lib/json/add/exception.rb +49 -0
  23. data/lib/json/add/ostruct.rb +54 -0
  24. data/lib/json/add/range.rb +54 -0
  25. data/lib/json/add/rational.rb +49 -0
  26. data/lib/json/add/regexp.rb +48 -0
  27. data/lib/json/add/set.rb +48 -0
  28. data/lib/json/add/struct.rb +52 -0
  29. data/lib/json/add/symbol.rb +48 -0
  30. data/lib/json/add/time.rb +59 -0
  31. data/lib/json/common.rb +588 -74
  32. data/lib/json/ext.rb +3 -1
  33. data/lib/json/generic_object.rb +75 -0
  34. data/lib/json/pure/generator.rb +311 -119
  35. data/lib/json/pure/parser.rb +182 -55
  36. data/lib/json/pure.rb +5 -65
  37. data/lib/json/version.rb +2 -1
  38. data/lib/json.rb +583 -196
  39. metadata +78 -137
  40. data/CHANGES +0 -25
  41. data/GPL +0 -340
  42. data/README +0 -77
  43. data/Rakefile +0 -250
  44. data/TODO +0 -1
  45. data/VERSION +0 -1
  46. data/benchmarks/benchmark.txt +0 -133
  47. data/benchmarks/benchmark_generator.rb +0 -44
  48. data/benchmarks/benchmark_parser.rb +0 -22
  49. data/benchmarks/benchmark_rails.rb +0 -26
  50. data/bin/edit_json.rb +0 -11
  51. data/data/example.json +0 -1
  52. data/data/index.html +0 -37
  53. data/data/prototype.js +0 -2515
  54. data/ext/json/ext/generator/Makefile +0 -149
  55. data/ext/json/ext/generator/unicode.c +0 -184
  56. data/ext/json/ext/generator/unicode.h +0 -40
  57. data/ext/json/ext/parser/Makefile +0 -149
  58. data/ext/json/ext/parser/unicode.c +0 -156
  59. data/ext/json/ext/parser/unicode.h +0 -44
  60. data/install.rb +0 -26
  61. data/lib/json/Array.xpm +0 -21
  62. data/lib/json/FalseClass.xpm +0 -21
  63. data/lib/json/Hash.xpm +0 -21
  64. data/lib/json/Key.xpm +0 -73
  65. data/lib/json/NilClass.xpm +0 -21
  66. data/lib/json/Numeric.xpm +0 -28
  67. data/lib/json/String.xpm +0 -96
  68. data/lib/json/TrueClass.xpm +0 -21
  69. data/lib/json/editor.rb +0 -1207
  70. data/lib/json/json.xpm +0 -1499
  71. data/tests/fixtures/fail1.json +0 -1
  72. data/tests/fixtures/fail10.json +0 -1
  73. data/tests/fixtures/fail11.json +0 -1
  74. data/tests/fixtures/fail12.json +0 -1
  75. data/tests/fixtures/fail13.json +0 -1
  76. data/tests/fixtures/fail14.json +0 -1
  77. data/tests/fixtures/fail15.json +0 -1
  78. data/tests/fixtures/fail16.json +0 -1
  79. data/tests/fixtures/fail17.json +0 -1
  80. data/tests/fixtures/fail19.json +0 -1
  81. data/tests/fixtures/fail2.json +0 -1
  82. data/tests/fixtures/fail20.json +0 -1
  83. data/tests/fixtures/fail21.json +0 -1
  84. data/tests/fixtures/fail22.json +0 -1
  85. data/tests/fixtures/fail23.json +0 -1
  86. data/tests/fixtures/fail24.json +0 -1
  87. data/tests/fixtures/fail25.json +0 -1
  88. data/tests/fixtures/fail26.json +0 -1
  89. data/tests/fixtures/fail27.json +0 -2
  90. data/tests/fixtures/fail28.json +0 -2
  91. data/tests/fixtures/fail3.json +0 -1
  92. data/tests/fixtures/fail4.json +0 -1
  93. data/tests/fixtures/fail5.json +0 -1
  94. data/tests/fixtures/fail6.json +0 -1
  95. data/tests/fixtures/fail7.json +0 -1
  96. data/tests/fixtures/fail8.json +0 -1
  97. data/tests/fixtures/fail9.json +0 -1
  98. data/tests/fixtures/pass1.json +0 -56
  99. data/tests/fixtures/pass18.json +0 -1
  100. data/tests/fixtures/pass2.json +0 -1
  101. data/tests/fixtures/pass3.json +0 -6
  102. data/tests/runner.rb +0 -24
  103. data/tests/test_json.rb +0 -235
  104. data/tests/test_json_addition.rb +0 -94
  105. data/tests/test_json_fixtures.rb +0 -30
  106. data/tests/test_json_generate.rb +0 -81
  107. data/tests/test_json_unicode.rb +0 -55
  108. data/tools/fuzz.rb +0 -133
  109. data/tools/server.rb +0 -62
@@ -1,149 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /usr/lib/ruby/1.8/i686-linux
8
- hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
10
- prefix = $(DESTDIR)/usr
11
- exec_prefix = $(prefix)
12
- sitedir = $(DESTDIR)/usr/lib/ruby/site_ruby
13
- rubylibdir = $(libdir)/ruby/$(ruby_version)
14
- docdir = $(datarootdir)/doc/$(PACKAGE)
15
- dvidir = $(docdir)
16
- datarootdir = $(prefix)/share
17
- archdir = $(rubylibdir)/$(arch)
18
- sbindir = $(exec_prefix)/sbin
19
- psdir = $(docdir)
20
- localedir = $(datarootdir)/locale
21
- htmldir = $(docdir)
22
- datadir = $(DESTDIR)/usr/share
23
- includedir = $(prefix)/include
24
- infodir = $(DESTDIR)/usr/share/info
25
- sysconfdir = $(DESTDIR)/etc
26
- mandir = $(DESTDIR)/usr/share/man
27
- libdir = $(exec_prefix)/lib
28
- sharedstatedir = $(prefix)/com
29
- oldincludedir = $(DESTDIR)/usr/include
30
- pdfdir = $(docdir)
31
- sitearchdir = $(sitelibdir)/$(sitearch)
32
- bindir = $(exec_prefix)/bin
33
- localstatedir = $(DESTDIR)/var/lib
34
- sitelibdir = $(sitedir)/$(ruby_version)
35
- libexecdir = $(exec_prefix)/libexec
36
-
37
- CC = i686-pc-linux-gnu-gcc -Wall -ggdb
38
- LIBRUBY = $(LIBRUBY_SO)
39
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
- LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -L. -l$(RUBY_SO_NAME)
41
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
42
-
43
- RUBY_EXTCONF_H =
44
- CFLAGS = -fPIC -march=pentium4 -O2 -pipe -ggdb -fPIC
45
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
46
- CPPFLAGS =
47
- CXXFLAGS = $(CFLAGS)
48
- DLDFLAGS =
49
- LDSHARED = $(CC) -shared
50
- AR = i686-pc-linux-gnu-ar
51
- EXEEXT =
52
-
53
- RUBY_INSTALL_NAME = ruby18
54
- RUBY_SO_NAME = ruby18
55
- arch = i686-linux
56
- sitearch = i686-linux
57
- ruby_version = 1.8
58
- ruby = /usr/bin/ruby18
59
- RUBY = $(ruby)
60
- RM = rm -f
61
- MAKEDIRS = mkdir -p
62
- INSTALL = /bin/install -c
63
- INSTALL_PROG = $(INSTALL) -m 0755
64
- INSTALL_DATA = $(INSTALL) -m 644
65
- COPY = cp
66
-
67
- #### End of system configuration section. ####
68
-
69
- preload =
70
-
71
- libpath = $(libdir)
72
- LIBPATH = -L'$(libdir)' -Wl,-R'$(libdir)'
73
- DEFFILE =
74
-
75
- CLEANFILES =
76
- DISTCLEANFILES =
77
-
78
- extout =
79
- extout_prefix =
80
- target_prefix =
81
- LOCAL_LIBS =
82
- LIBS = $(LIBRUBYARG_SHARED) -ldl -lcrypt -lm -lc
83
- SRCS = unicode.c generator.c
84
- OBJS = unicode.o generator.o
85
- TARGET = generator
86
- DLLIB = $(TARGET).so
87
- EXTSTATIC =
88
- STATIC_LIB =
89
-
90
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
91
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
92
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
93
-
94
- TARGET_SO = $(DLLIB)
95
- CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
96
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
97
-
98
- all: $(DLLIB)
99
- static: $(STATIC_LIB)
100
-
101
- clean:
102
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
103
-
104
- distclean: clean
105
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
106
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
107
-
108
- realclean: distclean
109
- install: install-so install-rb
110
-
111
- install-so: $(RUBYARCHDIR)
112
- install-so: $(RUBYARCHDIR)/$(DLLIB)
113
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
114
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
115
- install-rb: pre-install-rb install-rb-default
116
- install-rb-default: pre-install-rb-default
117
- pre-install-rb: Makefile
118
- pre-install-rb-default: Makefile
119
- $(RUBYARCHDIR):
120
- $(MAKEDIRS) $@
121
-
122
- site-install: site-install-so site-install-rb
123
- site-install-so: install-so
124
- site-install-rb: install-rb
125
-
126
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
127
-
128
- .cc.o:
129
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
130
-
131
- .cxx.o:
132
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
133
-
134
- .cpp.o:
135
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
136
-
137
- .C.o:
138
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
139
-
140
- .c.o:
141
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
142
-
143
- $(DLLIB): $(OBJS)
144
- @-$(RM) $@
145
- $(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
146
-
147
-
148
-
149
- $(OBJS): ruby.h defines.h
@@ -1,184 +0,0 @@
1
- /* vim: set cin et sw=4 ts=4: */
2
-
3
- #include "unicode.h"
4
-
5
- #define unicode_escape(buffer, character) \
6
- sprintf(buf, "\\u%04x", (unsigned int) (character)); \
7
- rb_str_buf_cat(buffer, buf, 6);
8
-
9
- /*
10
- * Copyright 2001-2004 Unicode, Inc.
11
- *
12
- * Disclaimer
13
- *
14
- * This source code is provided as is by Unicode, Inc. No claims are
15
- * made as to fitness for any particular purpose. No warranties of any
16
- * kind are expressed or implied. The recipient agrees to determine
17
- * applicability of information provided. If this file has been
18
- * purchased on magnetic or optical media from Unicode, Inc., the
19
- * sole remedy for any claim will be exchange of defective media
20
- * within 90 days of receipt.
21
- *
22
- * Limitations on Rights to Redistribute This Code
23
- *
24
- * Unicode, Inc. hereby grants the right to freely use the information
25
- * supplied in this file in the creation of products supporting the
26
- * Unicode Standard, and to make copies of this file in any form
27
- * for internal or external distribution as long as this notice
28
- * remains attached.
29
- */
30
-
31
- /*
32
- * Index into the table below with the first byte of a UTF-8 sequence to
33
- * get the number of trailing bytes that are supposed to follow it.
34
- * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
35
- * left as-is for anyone who may want to do such conversion, which was
36
- * allowed in earlier algorithms.
37
- */
38
- static const char trailingBytesForUTF8[256] = {
39
- 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,
40
- 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,
41
- 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,
42
- 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,
43
- 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,
44
- 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,
45
- 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,
46
- 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
47
- };
48
-
49
- /*
50
- * Magic values subtracted from a buffer value during UTF8 conversion.
51
- * This table contains as many values as there might be trailing bytes
52
- * in a UTF-8 sequence.
53
- */
54
- static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
55
- 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
56
-
57
- /*
58
- * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
59
- * into the first byte, depending on how many bytes follow. There are
60
- * as many entries in this table as there are UTF-8 sequence types.
61
- * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
62
- * for *legal* UTF-8 will be 4 or fewer bytes total.
63
- */
64
- static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
65
-
66
- /*
67
- * Utility routine to tell whether a sequence of bytes is legal UTF-8.
68
- * This must be called with the length pre-determined by the first byte.
69
- * If not calling this from ConvertUTF8to*, then the length can be set by:
70
- * length = trailingBytesForUTF8[*source]+1;
71
- * and the sequence is illegal right away if there aren't that many bytes
72
- * available.
73
- * If presented with a length > 4, this returns 0. The Unicode
74
- * definition of UTF-8 goes up to 4-byte sequences.
75
- */
76
-
77
- inline static unsigned char isLegalUTF8(const UTF8 *source, int length)
78
- {
79
- UTF8 a;
80
- const UTF8 *srcptr = source+length;
81
- switch (length) {
82
- default: return 0;
83
- /* Everything else falls through when "1"... */
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;
87
-
88
- switch (*source) {
89
- /* no fall-through in this inner switch */
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;
95
- }
96
-
97
- case 1: if (*source >= 0x80 && *source < 0xC2) return 0;
98
- }
99
- if (*source > 0xF4) return 0;
100
- return 1;
101
- }
102
-
103
- inline void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags)
104
- {
105
- char buf[7];
106
- const UTF8* source = (UTF8 *) RSTRING(string)->ptr;
107
- const UTF8* sourceEnd = source + RSTRING(string)->len;
108
-
109
- while (source < sourceEnd) {
110
- UTF32 ch = 0;
111
- unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
112
- if (source + extraBytesToRead >= sourceEnd) {
113
- rb_raise(rb_path2class("JSON::GeneratorError"),
114
- "partial character in source, but hit end");
115
- }
116
- if (!isLegalUTF8(source, extraBytesToRead+1)) {
117
- rb_raise(rb_path2class("JSON::GeneratorError"),
118
- "source sequence is illegal/malformed");
119
- }
120
- /*
121
- * The cases all fall through. See "Note A" below.
122
- */
123
- switch (extraBytesToRead) {
124
- case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
125
- case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
126
- case 3: ch += *source++; ch <<= 6;
127
- case 2: ch += *source++; ch <<= 6;
128
- case 1: ch += *source++; ch <<= 6;
129
- case 0: ch += *source++;
130
- }
131
- ch -= offsetsFromUTF8[extraBytesToRead];
132
-
133
- if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
134
- /* UTF-16 surrogate values are illegal in UTF-32 */
135
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
136
- if (flags == strictConversion) {
137
- source -= (extraBytesToRead+1); /* return to the illegal value itself */
138
- rb_raise(rb_path2class("JSON::GeneratorError"),
139
- "source sequence is illegal/malformed");
140
- } else {
141
- unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
142
- }
143
- } else {
144
- /* normal case */
145
- if (ch == '"') {
146
- rb_str_buf_cat2(buffer, "\\\"");
147
- } else if (ch == '\\') {
148
- rb_str_buf_cat2(buffer, "\\\\");
149
- } else if (ch == '/') {
150
- rb_str_buf_cat2(buffer, "\\/");
151
- } else if (ch >= 0x20 && ch <= 0x7f) {
152
- rb_str_buf_cat(buffer, (char *) source - 1, 1);
153
- } else if (ch == '\n') {
154
- rb_str_buf_cat2(buffer, "\\n");
155
- } else if (ch == '\r') {
156
- rb_str_buf_cat2(buffer, "\\r");
157
- } else if (ch == '\t') {
158
- rb_str_buf_cat2(buffer, "\\t");
159
- } else if (ch == '\f') {
160
- rb_str_buf_cat2(buffer, "\\f");
161
- } else if (ch == '\b') {
162
- rb_str_buf_cat2(buffer, "\\b");
163
- } else if (ch < 0x20) {
164
- unicode_escape(buffer, (UTF16) ch);
165
- } else {
166
- unicode_escape(buffer, (UTF16) ch);
167
- }
168
- }
169
- } else if (ch > UNI_MAX_UTF16) {
170
- if (flags == strictConversion) {
171
- source -= (extraBytesToRead+1); /* return to the start */
172
- rb_raise(rb_path2class("JSON::GeneratorError"),
173
- "source sequence is illegal/malformed");
174
- } else {
175
- unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
176
- }
177
- } else {
178
- /* target is a character in range 0xFFFF - 0x10FFFF. */
179
- ch -= halfBase;
180
- unicode_escape(buffer, (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START));
181
- unicode_escape(buffer, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START));
182
- }
183
- }
184
- }
@@ -1,40 +0,0 @@
1
- #include "ruby.h"
2
-
3
- #ifndef _GENERATOR_UNICODE_H_
4
- #define _GENERATOR_UNICODE_H_
5
-
6
- typedef enum {
7
- conversionOK = 0, /* conversion successful */
8
- sourceExhausted, /* partial character in source, but hit end */
9
- targetExhausted, /* insuff. room in target for conversion */
10
- sourceIllegal /* source sequence is illegal/malformed */
11
- } ConversionResult;
12
-
13
- typedef enum {
14
- strictConversion = 0,
15
- lenientConversion
16
- } ConversionFlags;
17
-
18
- typedef unsigned long UTF32; /* at least 32 bits */
19
- typedef unsigned short UTF16; /* at least 16 bits */
20
- typedef unsigned char UTF8; /* typically 8 bits */
21
-
22
- #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
23
- #define UNI_MAX_BMP (UTF32)0x0000FFFF
24
- #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
25
- #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
26
- #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
27
-
28
- #define UNI_SUR_HIGH_START (UTF32)0xD800
29
- #define UNI_SUR_HIGH_END (UTF32)0xDBFF
30
- #define UNI_SUR_LOW_START (UTF32)0xDC00
31
- #define UNI_SUR_LOW_END (UTF32)0xDFFF
32
-
33
- static const int halfShift = 10; /* used for shifting by 10 bits */
34
-
35
- static const UTF32 halfBase = 0x0010000UL;
36
- static const UTF32 halfMask = 0x3FFUL;
37
-
38
- void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags);
39
-
40
- #endif
@@ -1,149 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /usr/lib/ruby/1.8/i686-linux
8
- hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
10
- prefix = $(DESTDIR)/usr
11
- exec_prefix = $(prefix)
12
- sitedir = $(DESTDIR)/usr/lib/ruby/site_ruby
13
- rubylibdir = $(libdir)/ruby/$(ruby_version)
14
- docdir = $(datarootdir)/doc/$(PACKAGE)
15
- dvidir = $(docdir)
16
- datarootdir = $(prefix)/share
17
- archdir = $(rubylibdir)/$(arch)
18
- sbindir = $(exec_prefix)/sbin
19
- psdir = $(docdir)
20
- localedir = $(datarootdir)/locale
21
- htmldir = $(docdir)
22
- datadir = $(DESTDIR)/usr/share
23
- includedir = $(prefix)/include
24
- infodir = $(DESTDIR)/usr/share/info
25
- sysconfdir = $(DESTDIR)/etc
26
- mandir = $(DESTDIR)/usr/share/man
27
- libdir = $(exec_prefix)/lib
28
- sharedstatedir = $(prefix)/com
29
- oldincludedir = $(DESTDIR)/usr/include
30
- pdfdir = $(docdir)
31
- sitearchdir = $(sitelibdir)/$(sitearch)
32
- bindir = $(exec_prefix)/bin
33
- localstatedir = $(DESTDIR)/var/lib
34
- sitelibdir = $(sitedir)/$(ruby_version)
35
- libexecdir = $(exec_prefix)/libexec
36
-
37
- CC = i686-pc-linux-gnu-gcc -Wall
38
- LIBRUBY = $(LIBRUBY_SO)
39
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
- LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -L. -l$(RUBY_SO_NAME)
41
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
42
-
43
- RUBY_EXTCONF_H =
44
- CFLAGS = -fPIC -march=pentium4 -O2 -pipe -ggdb -fPIC
45
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
46
- CPPFLAGS =
47
- CXXFLAGS = $(CFLAGS)
48
- DLDFLAGS =
49
- LDSHARED = $(CC) -shared
50
- AR = i686-pc-linux-gnu-ar
51
- EXEEXT =
52
-
53
- RUBY_INSTALL_NAME = ruby18
54
- RUBY_SO_NAME = ruby18
55
- arch = i686-linux
56
- sitearch = i686-linux
57
- ruby_version = 1.8
58
- ruby = /usr/bin/ruby18
59
- RUBY = $(ruby)
60
- RM = rm -f
61
- MAKEDIRS = mkdir -p
62
- INSTALL = /bin/install -c
63
- INSTALL_PROG = $(INSTALL) -m 0755
64
- INSTALL_DATA = $(INSTALL) -m 644
65
- COPY = cp
66
-
67
- #### End of system configuration section. ####
68
-
69
- preload =
70
-
71
- libpath = $(libdir)
72
- LIBPATH = -L'$(libdir)' -Wl,-R'$(libdir)'
73
- DEFFILE =
74
-
75
- CLEANFILES =
76
- DISTCLEANFILES =
77
-
78
- extout =
79
- extout_prefix =
80
- target_prefix =
81
- LOCAL_LIBS =
82
- LIBS = $(LIBRUBYARG_SHARED) -ldl -lcrypt -lm -lc
83
- SRCS = parser.c unicode.c
84
- OBJS = parser.o unicode.o
85
- TARGET = parser
86
- DLLIB = $(TARGET).so
87
- EXTSTATIC =
88
- STATIC_LIB =
89
-
90
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
91
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
92
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
93
-
94
- TARGET_SO = $(DLLIB)
95
- CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
96
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
97
-
98
- all: $(DLLIB)
99
- static: $(STATIC_LIB)
100
-
101
- clean:
102
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
103
-
104
- distclean: clean
105
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
106
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
107
-
108
- realclean: distclean
109
- install: install-so install-rb
110
-
111
- install-so: $(RUBYARCHDIR)
112
- install-so: $(RUBYARCHDIR)/$(DLLIB)
113
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
114
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
115
- install-rb: pre-install-rb install-rb-default
116
- install-rb-default: pre-install-rb-default
117
- pre-install-rb: Makefile
118
- pre-install-rb-default: Makefile
119
- $(RUBYARCHDIR):
120
- $(MAKEDIRS) $@
121
-
122
- site-install: site-install-so site-install-rb
123
- site-install-so: install-so
124
- site-install-rb: install-rb
125
-
126
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
127
-
128
- .cc.o:
129
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
130
-
131
- .cxx.o:
132
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
133
-
134
- .cpp.o:
135
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
136
-
137
- .C.o:
138
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
139
-
140
- .c.o:
141
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
142
-
143
- $(DLLIB): $(OBJS)
144
- @-$(RM) $@
145
- $(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
146
-
147
-
148
-
149
- $(OBJS): ruby.h defines.h
@@ -1,156 +0,0 @@
1
- /* vim: set cin et sw=4 ts=4: */
2
-
3
- #include "unicode.h"
4
-
5
- /*
6
- * Copyright 2001-2004 Unicode, Inc.
7
- *
8
- * Disclaimer
9
- *
10
- * This source code is provided as is by Unicode, Inc. No claims are
11
- * made as to fitness for any particular purpose. No warranties of any
12
- * kind are expressed or implied. The recipient agrees to determine
13
- * applicability of information provided. If this file has been
14
- * purchased on magnetic or optical media from Unicode, Inc., the
15
- * sole remedy for any claim will be exchange of defective media
16
- * within 90 days of receipt.
17
- *
18
- * Limitations on Rights to Redistribute This Code
19
- *
20
- * Unicode, Inc. hereby grants the right to freely use the information
21
- * supplied in this file in the creation of products supporting the
22
- * Unicode Standard, and to make copies of this file in any form
23
- * for internal or external distribution as long as this notice
24
- * remains attached.
25
- */
26
-
27
- /*
28
- * Index into the table below with the first byte of a UTF-8 sequence to
29
- * get the number of trailing bytes that are supposed to follow it.
30
- * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
31
- * left as-is for anyone who may want to do such conversion, which was
32
- * allowed in earlier algorithms.
33
- */
34
- static const char trailingBytesForUTF8[256] = {
35
- 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,
36
- 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,
37
- 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,
38
- 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,
39
- 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,
40
- 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,
41
- 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,
42
- 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
43
- };
44
-
45
- /*
46
- * Magic values subtracted from a buffer value during UTF8 conversion.
47
- * This table contains as many values as there might be trailing bytes
48
- * in a UTF-8 sequence.
49
- */
50
- static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
51
- 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
52
-
53
- /*
54
- * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
55
- * into the first byte, depending on how many bytes follow. There are
56
- * as many entries in this table as there are UTF-8 sequence types.
57
- * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
58
- * for *legal* UTF-8 will be 4 or fewer bytes total.
59
- */
60
- static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
61
-
62
- inline char *JSON_convert_UTF16_to_UTF8 (
63
- VALUE buffer,
64
- char *source,
65
- char *sourceEnd,
66
- ConversionFlags flags)
67
- {
68
- UTF16 *tmp, *tmpPtr, *tmpEnd;
69
- char buf[5];
70
- long n = 0, i;
71
- char *p = source - 1;
72
-
73
- while (p < sourceEnd && p[0] == '\\' && p[1] == 'u') {
74
- p += 6;
75
- n++;
76
- }
77
- p = source + 1;
78
- buf[4] = 0;
79
- tmpPtr = tmp = ALLOC_N(UTF16, n);
80
- tmpEnd = tmp + n;
81
- for (i = 0; i < n; i++) {
82
- buf[0] = *p++;
83
- buf[1] = *p++;
84
- buf[2] = *p++;
85
- buf[3] = *p++;
86
- tmpPtr[i] = strtol(buf, NULL, 16);
87
- p += 2;
88
- }
89
-
90
- while (tmpPtr < tmpEnd) {
91
- UTF32 ch;
92
- unsigned short bytesToWrite = 0;
93
- const UTF32 byteMask = 0xBF;
94
- const UTF32 byteMark = 0x80;
95
- ch = *tmpPtr++;
96
- /* If we have a surrogate pair, convert to UTF32 first. */
97
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
98
- /* If the 16 bits following the high surrogate are in the source
99
- * buffer... */
100
- if (tmpPtr < tmpEnd) {
101
- UTF32 ch2 = *tmpPtr;
102
- /* If it's a low surrogate, convert to UTF32. */
103
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
104
- ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
105
- + (ch2 - UNI_SUR_LOW_START) + halfBase;
106
- ++tmpPtr;
107
- } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
108
- free(tmp);
109
- rb_raise(rb_path2class("JSON::ParserError"),
110
- "source sequence is illegal/malformed near %s", source);
111
- }
112
- } else { /* We don't have the 16 bits following the high surrogate. */
113
- free(tmp);
114
- rb_raise(rb_path2class("JSON::ParserError"),
115
- "partial character in source, but hit end near %s", source);
116
- break;
117
- }
118
- } else if (flags == strictConversion) {
119
- /* UTF-16 surrogate values are illegal in UTF-32 */
120
- if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
121
- free(tmp);
122
- rb_raise(rb_path2class("JSON::ParserError"),
123
- "source sequence is illegal/malformed near %s", source);
124
- }
125
- }
126
- /* Figure out how many bytes the result will require */
127
- if (ch < (UTF32) 0x80) {
128
- bytesToWrite = 1;
129
- } else if (ch < (UTF32) 0x800) {
130
- bytesToWrite = 2;
131
- } else if (ch < (UTF32) 0x10000) {
132
- bytesToWrite = 3;
133
- } else if (ch < (UTF32) 0x110000) {
134
- bytesToWrite = 4;
135
- } else {
136
- bytesToWrite = 3;
137
- ch = UNI_REPLACEMENT_CHAR;
138
- }
139
-
140
- buf[0] = 0;
141
- buf[1] = 0;
142
- buf[2] = 0;
143
- buf[3] = 0;
144
- p = buf + bytesToWrite;
145
- switch (bytesToWrite) { /* note: everything falls through. */
146
- case 4: *--p = (UTF8) ((ch | byteMark) & byteMask); ch >>= 6;
147
- case 3: *--p = (UTF8) ((ch | byteMark) & byteMask); ch >>= 6;
148
- case 2: *--p = (UTF8) ((ch | byteMark) & byteMask); ch >>= 6;
149
- case 1: *--p = (UTF8) (ch | firstByteMark[bytesToWrite]);
150
- }
151
- rb_str_buf_cat(buffer, p, bytesToWrite);
152
- }
153
- free(tmp);
154
- source += 5 + (n - 1) * 6;
155
- return source;
156
- }