removed deprecated RegexpOfHolding

This commit is contained in:
Kyle Banker 2010-04-07 16:32:25 -04:00
parent 3d3e983ae0
commit e18d2d6fbb
6 changed files with 3 additions and 74 deletions

View File

@ -12,6 +12,7 @@
you may want to remove you may want to remove
* Removed the following deprecated items: * Removed the following deprecated items:
* GridStore class * GridStore class
* RegexpOfHolding class
* BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes). * BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes).
* mongo_ext no longer exists. * mongo_ext no longer exists.

View File

@ -63,7 +63,6 @@ static VALUE Code;
static VALUE MinKey; static VALUE MinKey;
static VALUE MaxKey; static VALUE MaxKey;
static VALUE Regexp; static VALUE Regexp;
static VALUE RegexpOfHolding;
static VALUE OrderedHash; static VALUE OrderedHash;
static VALUE InvalidKeyName; static VALUE InvalidKeyName;
static VALUE InvalidStringEncoding; static VALUE InvalidStringEncoding;
@ -687,12 +686,10 @@ static VALUE get_value(const char* buffer, int* position, int type) {
int pattern_length = strlen(buffer + *position); int pattern_length = strlen(buffer + *position);
VALUE pattern = STR_NEW(buffer + *position, pattern_length); VALUE pattern = STR_NEW(buffer + *position, pattern_length);
int flags_length, flags = 0, i = 0; int flags_length, flags = 0, i = 0;
char extra[10];
VALUE argv[3]; VALUE argv[3];
*position += pattern_length + 1; *position += pattern_length + 1;
flags_length = strlen(buffer + *position); flags_length = strlen(buffer + *position);
extra[0] = 0;
for (i = 0; i < flags_length; i++) { for (i = 0; i < flags_length; i++) {
char flag = buffer[*position + i]; char flag = buffer[*position + i];
if (flag == 'i') { if (flag == 'i') {
@ -704,19 +701,10 @@ static VALUE get_value(const char* buffer, int* position, int type) {
else if (flag == 'x') { else if (flag == 'x') {
flags |= EXTENDED; flags |= EXTENDED;
} }
else if (strlen(extra) < 9) {
strncat(extra, &flag, 1);
}
} }
argv[0] = pattern; argv[0] = pattern;
argv[1] = INT2FIX(flags); argv[1] = INT2FIX(flags);
if(extra[0] == 0) {
value = rb_class_new_instance(2, argv, Regexp); value = rb_class_new_instance(2, argv, Regexp);
}
else { // Deserializing a RegexpOfHolding
argv[2] = rb_str_new2(extra);
value = rb_class_new_instance(3, argv, RegexpOfHolding);
}
*position += flags_length + 1; *position += flags_length + 1;
break; break;
} }
@ -900,7 +888,6 @@ void Init_cbson() {
MaxKey = rb_const_get(bson, rb_intern("MaxKey")); MaxKey = rb_const_get(bson, rb_intern("MaxKey"));
rb_require("bson/types/regexp_of_holding"); rb_require("bson/types/regexp_of_holding");
Regexp = rb_const_get(rb_cObject, rb_intern("Regexp")); Regexp = rb_const_get(rb_cObject, rb_intern("Regexp"));
RegexpOfHolding = rb_const_get(bson, rb_intern("RegexpOfHolding"));
rb_require("bson/exceptions"); rb_require("bson/exceptions");
InvalidKeyName = rb_const_get(bson, rb_intern("InvalidKeyName")); InvalidKeyName = rb_const_get(bson, rb_intern("InvalidKeyName"));
InvalidStringEncoding = rb_const_get(bson, rb_intern("InvalidStringEncoding")); InvalidStringEncoding = rb_const_get(bson, rb_intern("InvalidStringEncoding"));

View File

@ -36,7 +36,6 @@ require 'bson/types/binary'
require 'bson/types/code' require 'bson/types/code'
require 'bson/types/dbref' require 'bson/types/dbref'
require 'bson/types/objectid' require 'bson/types/objectid'
require 'bson/types/regexp_of_holding'
require 'bson/types/min_max_keys' require 'bson/types/min_max_keys'
require 'base64' require 'base64'

View File

@ -322,13 +322,7 @@ module BSON
options |= Regexp::IGNORECASE if options_str.include?('i') options |= Regexp::IGNORECASE if options_str.include?('i')
options |= Regexp::MULTILINE if options_str.include?('m') options |= Regexp::MULTILINE if options_str.include?('m')
options |= Regexp::EXTENDED if options_str.include?('x') options |= Regexp::EXTENDED if options_str.include?('x')
options_str.gsub!(/[imx]/, '') # Now remove the three we understand
if options_str == ''
Regexp.new(str, options) Regexp.new(str, options)
else
warn("Using deprecated Regexp options #{options_str}; future versions of this MongoDB driver will support only i, m, and x. See deprecated class RegexpOfHolding for more info.")
RegexpOfHolding.new(str, options, options_str)
end
end end
def deserialize_string_data(buf) def deserialize_string_data(buf)

View File

@ -1,45 +0,0 @@
# --
# Copyright (C) 2008-2010 10gen Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ++
module BSON
# A Regexp that can hold on to extra options and ignore them. Mongo
# regexes may contain option characters beyond 'i', 'm', and 'x'. (Note
# that Mongo only uses those three, but that regexes coming from other
# languages may store different option characters.)
#
# Note that you do not have to use this class at all if you wish to
# store regular expressions in Mongo. The Mongo and Ruby regex option
# flags are the same. Storing regexes is discouraged, in any case.
#
# @deprecated
class RegexpOfHolding < Regexp
attr_accessor :extra_options_str
# @deprecated we're no longer supporting this.
# +str+ and +options+ are the same as Regexp. +extra_options_str+
# contains all the other flags that were in Mongo but we do not use or
# understand.
def initialize(str, options, extra_options_str)
warn "RegexpOfHolding is deprecated; the modifiers i, m, and x will be stored automatically as BSON." +
"If you're only storing the options i, m, and x, you can safely ignore this message."
super(str, options)
@extra_options_str = extra_options_str
end
end
end

View File

@ -153,18 +153,11 @@ class BSONTest < Test::Unit::TestCase
r = doc2['doc'] r = doc2['doc']
assert_kind_of Regexp, r assert_kind_of Regexp, r
r = RegexpOfHolding.new('st', 0, 'zywcab')
assert_equal 'zywcab', r.extra_options_str
doc = {'doc' => r} doc = {'doc' => r}
bson_doc = BSON::BSON_CODER.serialize(doc) bson_doc = BSON::BSON_CODER.serialize(doc)
doc2 = nil doc2 = nil
doc2 = BSON::BSON_CODER.deserialize(bson_doc) doc2 = BSON::BSON_CODER.deserialize(bson_doc)
assert_equal doc, doc2 assert_equal doc, doc2
r = doc2['doc']
assert_kind_of RegexpOfHolding, r
assert_equal 'abcwyz', r.extra_options_str # must be sorted
end end
def test_boolean def test_boolean