Class: Mustang::V8::Regexp

Inherits:
Value show all
Includes:
Delegated
Defined in:
lib/mustang/v8/regexp.rb,
ext/v8/v8_regexp.cpp

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegated

#method_missing, #old_method_missing, #old_respond_to?, #respond_to?, #to_s

Methods inherited from Value

#array?, #ary?, #bool?, #boolean?, #date?, #empty?, #external?, #false?, #func?, #function?, #int?, #integer?, #null?, #num?, #number?, #obj?, #object?, #regex?, #regexp?, #str?, #string?, #to_boolean, #to_integer, #to_number, #to_object, #to_string, #true?, #undefined?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Delegated

Class Method Details

.V8::Regexp.new(rxp) ⇒ Regexp .V8::Regexp.new(str, flags) ⇒ Regexp

Returns new V8 regexp reflected from given ruby regexp or source and flags.

Overloads:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/v8/v8_regexp.cpp', line 61

static VALUE rb_v8_regexp_new(int argc, VALUE *argv, VALUE klass)
{
  HandleScope scope;
  PREVENT_CREATION_WITHOUT_CONTEXT();

  if (argc == 1) {
    return v8_ref_new(klass, to_v8_regexp(argv[0]));
  } else if (argc == 2) {
    return v8_ref_new(klass, to_v8_regexp(argv[0], argv[1]));
  } else {
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
    return Qnil;
  }
  
}

Instance Method Details

#==(other) ⇒ Object



6
7
8
# File 'lib/mustang/v8/regexp.rb', line 6

def ==(other)
  to_regexp == other
end

#===(other) ⇒ Object



10
11
12
# File 'lib/mustang/v8/regexp.rb', line 10

def ===(other)
  to_regexp == other
end

#delegateObject



14
15
16
# File 'lib/mustang/v8/regexp.rb', line 14

def delegate
  to_regexp
end

#optionsInteger

Returns fixnum value of v8 regexp flags.

Returns:



100
101
102
103
104
# File 'ext/v8/v8_regexp.cpp', line 100

static VALUE rb_v8_regexp_flags(VALUE self)
{
  HandleScope scope;
  return to_ruby(unwrap(self)->GetFlags());
}

#flagsInteger

Returns fixnum value of ruby regexp flags.

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'ext/v8/v8_regexp.cpp', line 113

static VALUE rb_v8_regexp_options(VALUE self)
{
  HandleScope scope;
  int flags = (int)unwrap(self)->GetFlags();
  int opts = 0;

  if (flags & RegExp::kIgnoreCase) {
    opts |= 1; // Regexp::IGNORECASE
  }
  if (flags & RegExp::kGlobal) {
    opts |= 2; // Regexp::EXTENDED
  }
  if (flags & RegExp::kMultiline) {
    opts |= 4; // Regexp::MULTILINE
  }
  
  return to_ruby(opts);
}

#sourceString

Returns regexp source string.

rxp = V8::Regexp.new(/foo(bar)?/i)
rxp.source # => "foo(bar)?"

Returns:



87
88
89
90
91
# File 'ext/v8/v8_regexp.cpp', line 87

static VALUE rb_v8_regexp_source(VALUE self)
{
  HandleScope scope;
  return to_ruby(unwrap(self)->GetSource());
}

#to_regexpObject



18
19
20
# File 'lib/mustang/v8/regexp.rb', line 18

def to_regexp
  ::Regexp.new(source, options)
end