Пример #1
0
static VALUE objectid_from_string(VALUE self, VALUE str)
{
    VALUE oid;
    int i;

    if (!legal_objectid_str(str)) {
      if (TYPE(str) == T_STRING) {
        rb_raise(InvalidObjectId, "illegal ObjectId format: %s", RSTRING_PTR(str));
      } else {
        VALUE inspect;
        inspect = rb_funcall(str, rb_intern("to_s"), 0);
        rb_raise(InvalidObjectId, "not a String: %s", (char *)inspect);
      }
    }

    oid = rb_ary_new2(12);

    for(i = 0; i < 12; i++) {
        rb_ary_store(oid, i, INT2FIX( (unsigned)(hexbyte( RSTRING_PTR(str)[2*i] ) << 4 ) | hexbyte( RSTRING_PTR(str)[2*i + 1] )));
    }

    return rb_class_new_instance(1, &oid, ObjectId);
}
Пример #2
0
static VALUE objectid_legal(VALUE self, VALUE str)
{
    if (legal_objectid_str(str))
        return Qtrue;
    return Qfalse;
}