oniguruma 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,13 @@
1
+ == 1.1.0 /
2
+ * Fixed string escaping in ORegexp#to_str and ORegexp#inspect.
3
+ * Added begin parameter to ORegexp#match.
4
+
1
5
  == 1.0.1 / 2007-03-28
2
6
  * Minimal recommended version of oniglib changed to be compatible with Ruby 1.9, now is 4.6 or higher.
3
7
  * Restore check for onig version to build with 4.6
4
8
  * In getting replacement do not create temp string object, but directly add to resulting buffer (performance impr.)
9
+ * Included binary gems for windows.
10
+ * Modified Rakefile to support win32 gems.
5
11
 
6
12
  == 1.0.0 / 2007-03-27
7
13
  * Added documentation for MatchData.
data/README.txt CHANGED
@@ -24,7 +24,7 @@ Consult the Syntax.txt[link:files/Syntax_txt.html] page.
24
24
 
25
25
  == REQUIREMENTS:
26
26
 
27
- * Oniguruma[http://www.geocities.jp/kosako3/oniguruma/] library v. 5.5 or higher
27
+ * Oniguruma[http://www.geocities.jp/kosako3/oniguruma/] library v. 4.6 or higher
28
28
 
29
29
  == INSTALL:
30
30
 
data/Rakefile CHANGED
@@ -4,13 +4,13 @@ require 'hoe'
4
4
  class Hoe
5
5
  # Dirty hack to eliminate Hoe from gem dependencies
6
6
  def extra_deps
7
- @extra_deps.reject { |x| Array(x).first == 'hoe' }
7
+ @extra_deps.delete_if{ |x| x.first == 'hoe' }
8
8
  end
9
9
 
10
10
  # Dirty hack to package only the required files per platform
11
11
  def spec= s
12
12
  if ENV['PLATFORM'] =~ /win32/
13
- s.files = s.files.reject! {|f| f =~ /ext\//}
13
+ s.files = s.files.reject! {|f| f =~ /extconf\.rb/}
14
14
  else
15
15
  s.files = s.files.reject! {|f| f =~ /win\//}
16
16
  end
@@ -2,7 +2,7 @@
2
2
  #include <oniguruma.h>
3
3
  /*
4
4
  TODO:
5
- - Add named backreferences.
5
+ - Complete oregexp_match with range parameter.
6
6
  */
7
7
 
8
8
  typedef struct _oregexp {
@@ -181,24 +181,53 @@ static VALUE oregexp_make_match_data(ORegexp * oregexp, OnigRegion * region, VAL
181
181
 
182
182
  /*
183
183
  * call-seq:
184
- * rxp.match(str) => matchdata or nil
184
+ * rxp.match(str) => matchdata or nil
185
+ * rxp.match(str, begin, end) => matchdata or nil
185
186
  *
186
187
  * Returns a <code>MatchData</code> object describing the match, or
187
188
  * <code>nil</code> if there was no match. This is equivalent to retrieving the
188
189
  * value of the special variable <code>$~</code> following a normal match.
189
190
  *
190
- * /(.)(.)(.)/.match("abc")[2] #=> "b"
191
+ * ORegexp.new('(.)(.)(.)').match("abc")[2] #=> "b"
192
+ *
193
+ * The second form allows to perform the match in a region
194
+ * defined by <code>begin</code> and <code>end</code> while
195
+ * still taking into account look-behinds and look-forwards.
196
+ *
197
+ * ORegexp.new('1*2*').match('11221122').offset => [4,8]
198
+ * ORegexp.new('(?<=2)1*2*').match('11221122').offset => [4,8]
199
+ *
200
+ * Compare with:
201
+ *
202
+ * ORegexp.new('(?<=2)1*2*').match('11221122'[4..-1]) => nil
191
203
  */
192
- static VALUE oregexp_match( VALUE self, VALUE string ) {
204
+ static VALUE oregexp_match( int argc, VALUE * argv, VALUE self ) {
193
205
  ORegexp *oregexp;
194
206
  Data_Get_Struct( self, ORegexp, oregexp );
195
-
196
- VALUE string_str = StringValue( string );
207
+
208
+
209
+ if ( argc == 0 || argc > 2) {
210
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
211
+ exit;
212
+ }
213
+
214
+ VALUE string_str = StringValue( argv[0] );
197
215
  UChar* str_ptr = RSTRING(string_str)->ptr;
198
216
  int str_len = RSTRING(string_str)->len;
217
+
218
+ int begin = 0;
219
+ int end = str_len;
220
+
221
+ if (argc > 1 ) {
222
+ begin = NUM2INT( argv[1] );
223
+ }
224
+ // if (argc > 2) {
225
+ // end = NUM2INT( argv[2] );
226
+ // }
227
+
199
228
 
200
229
  OnigRegion *region = onig_region_new();
201
- int r = onig_search(oregexp->reg, str_ptr, str_ptr + str_len, str_ptr, str_ptr + str_len, region, ONIG_OPTION_NONE);
230
+ int r = onig_search(oregexp->reg, str_ptr, str_ptr + str_len, str_ptr + begin, str_ptr + end, region, ONIG_OPTION_NONE);
202
231
  rb_backref_set(Qnil);
203
232
  if (r >= 0) {
204
233
  VALUE matchData = oregexp_make_match_data( oregexp, region, string_str);
@@ -642,6 +671,7 @@ static VALUE oregexp_m_scan(VALUE self, VALUE str) {
642
671
  return rb_ensure( oregexp_packed_scan, (VALUE)&call_args, oregexp_cleanup_region, (VALUE)region);
643
672
  }
644
673
 
674
+
645
675
  /**
646
676
  * call-seq:
647
677
  * rxp === str => true or false
@@ -671,7 +701,8 @@ static VALUE oregexp_m_eqq(VALUE self, VALUE str) {
671
701
  }
672
702
  }
673
703
  StringValue(str);
674
- match = oregexp_match(self, str);
704
+ VALUE args[] = {str};
705
+ match = oregexp_match(1, args, self);
675
706
  if (Qnil == match) {
676
707
  return Qfalse;
677
708
  }
@@ -689,7 +720,8 @@ static VALUE oregexp_m_eqq(VALUE self, VALUE str) {
689
720
  * ORegexp.new( 'SIT', :options => OPTION_IGNORECASE ) =~ "insensitive" #=> 5
690
721
  **/
691
722
  static VALUE oregexp_match_op(VALUE self, VALUE str) {
692
- VALUE ret = oregexp_match(self, str);
723
+ VALUE args[] = {str};
724
+ VALUE ret = oregexp_match(1, args, self);
693
725
  if(ret == Qnil)
694
726
  return Qnil;
695
727
  return INT2FIX(RMATCH(ret)->regs->beg[0]);
@@ -700,7 +732,7 @@ void Init_oregexp() {
700
732
  VALUE cORegexp = rb_define_class_under(mOniguruma, "ORegexp", rb_cObject);
701
733
  rb_define_alloc_func(cORegexp, oregexp_allocate);
702
734
  rb_define_method( cORegexp, "initialize", oregexp_initialize, 2 );
703
- rb_define_method( cORegexp, "match", oregexp_match, 1 );
735
+ rb_define_method( cORegexp, "match", oregexp_match, -1 );
704
736
  rb_define_method( cORegexp, "=~", oregexp_match_op, 1 );
705
737
  rb_define_method( cORegexp, "gsub", oregexp_m_gsub, -1 );
706
738
  rb_define_method( cORegexp, "sub", oregexp_m_sub, -1 );
@@ -256,7 +256,7 @@ module Oniguruma
256
256
  opt_str += "x" if (@options[:options] & OPTION_EXTEND) == 0
257
257
  end
258
258
  opt_str += ")"
259
- opt_str + ORegexp.escape( @pattern )
259
+ opt_str + @pattern
260
260
  end
261
261
 
262
262
 
@@ -273,7 +273,7 @@ module Oniguruma
273
273
  opt_str += "i" if (@options[:options] & OPTION_IGNORECASE) > 0
274
274
  opt_str += "m" if (@options[:options] & OPTION_MULTILINE) > 0
275
275
  opt_str += "x" if (@options[:options] & OPTION_EXTEND) > 0
276
- "/" + ORegexp.escape( @pattern ) + "/" + opt_str
276
+ "/" + @pattern + "/" + opt_str
277
277
  end
278
278
 
279
279
  # call-seq:
@@ -35,6 +35,16 @@ class ORegexpTestCase < Test::Unit::TestCase
35
35
  def test_match
36
36
  reg = Oniguruma::ORegexp.new( "(3.)(.*)(3.)" )
37
37
  assert_not_nil( reg.match( "12345634" ) )
38
+
39
+ reg = Oniguruma::ORegexp.new( '1+2+')
40
+ s = "11221122"
41
+ assert_equal( [0,4], reg.match( s ).offset )
42
+ assert_equal( [1,4], reg.match( s, 1 ).offset )
43
+ assert_equal( [4,8], reg.match( s, 2).offset )
44
+
45
+ reg = Oniguruma::ORegexp.new( '(?<=2)1+2+')
46
+ assert_equal( [4,8], reg.match( s, 4 ).offset )
47
+ assert_equal( nil, reg.match( s[4..-1] ) )
38
48
  end
39
49
 
40
50
  def test_no_match
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: oniguruma
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2007-03-28 00:00:00 +02:00
6
+ version: 1.1.0
7
+ date: 2007-05-10 00:00:00 +02:00
8
8
  summary: Bindings for the oniguruma regular expression library
9
9
  require_paths:
10
10
  - lib