bson_ext 0.20

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.
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright 2009-2010 10gen, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include "encoding_helpers.h"
18
+
19
+ /*
20
+ * Portions Copyright 2001 Unicode, Inc.
21
+ *
22
+ * Disclaimer
23
+ *
24
+ * This source code is provided as is by Unicode, Inc. No claims are
25
+ * made as to fitness for any particular purpose. No warranties of any
26
+ * kind are expressed or implied. The recipient agrees to determine
27
+ * applicability of information provided. If this file has been
28
+ * purchased on magnetic or optical media from Unicode, Inc., the
29
+ * sole remedy for any claim will be exchange of defective media
30
+ * within 90 days of receipt.
31
+ *
32
+ * Limitations on Rights to Redistribute This Code
33
+ *
34
+ * Unicode, Inc. hereby grants the right to freely use the information
35
+ * supplied in this file in the creation of products supporting the
36
+ * Unicode Standard, and to make copies of this file in any form
37
+ * for internal or external distribution as long as this notice
38
+ * remains attached.
39
+ */
40
+
41
+ /*
42
+ * Index into the table below with the first byte of a UTF-8 sequence to
43
+ * get the number of trailing bytes that are supposed to follow it.
44
+ */
45
+ static const char trailingBytesForUTF8[256] = {
46
+ 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,
47
+ 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,
48
+ 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,
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
+ 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,
53
+ 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
54
+ };
55
+
56
+ /* --------------------------------------------------------------------- */
57
+
58
+ /*
59
+ * Utility routine to tell whether a sequence of bytes is legal UTF-8.
60
+ * This must be called with the length pre-determined by the first byte.
61
+ * The length can be set by:
62
+ * length = trailingBytesForUTF8[*source]+1;
63
+ * and the sequence is illegal right away if there aren't that many bytes
64
+ * available.
65
+ * If presented with a length > 4, this returns 0. The Unicode
66
+ * definition of UTF-8 goes up to 4-byte sequences.
67
+ */
68
+ static unsigned char isLegalUTF8(const unsigned char* source, int length) {
69
+ unsigned char a;
70
+ const unsigned char* srcptr = source + length;
71
+ switch (length) {
72
+ default: return 0;
73
+ /* Everything else falls through when "true"... */
74
+ case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
75
+ case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
76
+ case 2: if ((a = (*--srcptr)) > 0xBF) return 0;
77
+ switch (*source) {
78
+ /* no fall-through in this inner switch */
79
+ case 0xE0: if (a < 0xA0) return 0; break;
80
+ case 0xF0: if (a < 0x90) return 0; break;
81
+ case 0xF4: if (a > 0x8F) return 0; break;
82
+ default: if (a < 0x80) return 0;
83
+ }
84
+ case 1: if (*source >= 0x80 && *source < 0xC2) return 0;
85
+ if (*source > 0xF4) return 0;
86
+ }
87
+ return 1;
88
+ }
89
+
90
+ result_t check_string(const unsigned char* string, const int length,
91
+ const char check_utf8, const char check_null) {
92
+ int position = 0;
93
+ /* By default we go character by character. Will be different for checking
94
+ * UTF-8 */
95
+ int sequence_length = 1;
96
+
97
+ if (!check_utf8 && !check_null) {
98
+ return VALID;
99
+ }
100
+
101
+ while (position < length) {
102
+ if (check_null && *(string + position) == 0) {
103
+ return HAS_NULL;
104
+ }
105
+ if (check_utf8) {
106
+ sequence_length = trailingBytesForUTF8[*(string + position)] + 1;
107
+ if ((position + sequence_length) > length) {
108
+ return NOT_UTF_8;
109
+ }
110
+ if (!isLegalUTF8(string + position, sequence_length)) {
111
+ return NOT_UTF_8;
112
+ }
113
+ }
114
+ position += sequence_length;
115
+ }
116
+
117
+ return VALID;
118
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright 2009-2010 10gen, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef ENCODING_HELPERS_H
18
+ #define ENCODING_HELPERS_H
19
+
20
+ typedef enum {
21
+ VALID,
22
+ NOT_UTF_8,
23
+ HAS_NULL
24
+ } result_t;
25
+
26
+ result_t check_string(const unsigned char* string, const int length,
27
+ const char check_utf8, const char check_null);
28
+
29
+ #endif
@@ -0,0 +1,10 @@
1
+ require 'mkmf'
2
+
3
+ have_func("asprintf")
4
+
5
+ have_header("ruby/st.h") || have_header("st.h")
6
+ have_header("ruby/regex.h") || have_header("regex.h")
7
+ have_header("ruby/encoding.h")
8
+
9
+ dir_config('cbson')
10
+ create_makefile('bson_ext/cbson')
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2009-2010 10gen, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #define VERSION "0.20"
@@ -0,0 +1 @@
1
+ puts "hello world"
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bson_ext
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 20
8
+ version: "0.20"
9
+ platform: ruby
10
+ authors:
11
+ - Mike Dirolf
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-04-07 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: C extensions to accelerate the Ruby BSON serialization. For more information about BSON, see http://bsonspec.org. For information about MongoDB, see http://www.mongodb.org.
21
+ email: mongodb-dev@googlegroups.com
22
+ executables: []
23
+
24
+ extensions:
25
+ - ext/cbson/extconf.rb
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - Rakefile
30
+ - bson_ext.gemspec
31
+ - ext/cbson/extconf.rb
32
+ - ext/lib/bson_ext.rb
33
+ - ext/cbson/buffer.c
34
+ - ext/cbson/cbson.c
35
+ - ext/cbson/encoding_helpers.c
36
+ - ext/cbson/buffer.h
37
+ - ext/cbson/encoding_helpers.h
38
+ - ext/cbson/version.h
39
+ has_rdoc: false
40
+ homepage: http://www.mongodb.org
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - ext
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.6
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: C extensions for Ruby BSON.
69
+ test_files: []
70
+