- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mrbgems/mruby-onig-regexp/mrblib/onig_regexp.rb
r321 r439 16 16 end 17 17 18 def self.last_match=(match) 19 @last_match = match 20 end 21 18 22 # ISO 15.2.15.7.2 19 23 def initialize_copy(other) … … 24 28 def ===(str) 25 29 not self.match(str).nil? 30 rescue TypeError 31 false 26 32 end 27 33 … … 46 52 end 47 53 54 # ISO 15.2.10.5.27 55 def match(re, pos=0, &block) 56 re.match(self, pos, &block) 57 end 58 59 48 60 # redefine methods with oniguruma regexp version 49 [:sub, :gsub, :split, :scan].each do |v|50 alias_method "string_#{v}".to_sym, v51 alias_method v, "onig_regexp_#{v}".to_sym61 %i[sub gsub split scan].each do |v| 62 alias_method :"string_#{v}", v if method_defined?(v) 63 alias_method v, :"onig_regexp_#{v}" 52 64 end 65 66 alias_method :match?, :onig_regexp_match? 53 67 54 68 alias_method :old_slice, :slice 55 69 alias_method :old_square_brancket, :[] 70 alias_method :old_square_brancket_equal, :[]= 56 71 57 72 def [](*args) … … 78 93 79 94 alias_method :slice, :[] 95 96 def []=(*args) 97 return old_square_brancket_equal(*args) unless args[0].class == Regexp 98 99 n_args = args.size 100 case n_args 101 when 2 102 match = args[0].match(self) 103 self[match.begin(0)...match.end(0)] = args[1] 104 when 3 105 match = args[0].match(self) 106 n = args[1] 107 self[match.begin(n)...match.end(n)] = args[2] 108 else 109 raise ArgumentError, "wrong number of arguments (#{n_args} for 2..3)" 110 end 111 112 self 113 end 80 114 81 115 def slice!(*args)
Note:
See TracChangeset
for help on using the changeset viewer.