Closed kou closed 5 years ago
Thanks! Does this fix https://github.com/mattn/mruby-onig-regexp/issues/95 ?
Unfortunately, this is unrelated.
For #95, we need to implement String#[]=
and Regexp.last_match=
something like this:
diff --git a/mrblib/onig_regexp.rb b/mrblib/onig_regexp.rb
index 3efb7cd..cce556b 100644
--- a/mrblib/onig_regexp.rb
+++ b/mrblib/onig_regexp.rb
@@ -15,6 +15,10 @@ class OnigRegexp
@last_match
end
+ def self.last_match=(match)
+ @last_match = match
+ end
+
# ISO 15.2.15.7.2
def initialize_copy(other)
initialize(other.source, other.options)
@@ -65,6 +69,7 @@ class String
alias_method :old_slice, :slice
alias_method :old_square_brancket, :[]
+ alias_method :old_square_brancket_equal, :[]=
def [](*args)
return old_square_brancket(*args) unless args[0].class == Regexp
@@ -90,6 +95,25 @@ class String
alias_method :slice, :[]
+ def []=(*args)
+ return old_square_brancket_equal(*args) unless args[0].class == Regexp
+
+ n_args = args.size
+ case n_args
+ when 2
+ match = args[0].match(self)
+ self[match.begin(0)...match.end(0)] = args[1]
+ when 3
+ match = args[0].match(self)
+ n = args[1]
+ self[match.begin(n)...match.end(n)] = args[2]
+ else
+ raise ArgumentError, "wrong number of arguments (#{n_args} for 2..3)"
+ end
+
+ self
+ end
+
def slice!(*args)
if args.size < 2
result = slice(*args)
Thank you. Could you update your pull-request to include above changes?
Should we include a fix for #95 into this? I can create a new pull request for #95. I think that it's better that we use separated pull requests because they are unrelated.
If it does not consume your time, please do, thank you.
OK. I'll create a new pull request. Could you merge this pull request as is?
Done: #97
Thank you so much.
Because mruby removes String#match at https://github.com/mruby/mruby/commit/fd37bc53deb2d52fe3134838eab002dfb9ac35ab .