File: regexp-util.rb

package info (click to toggle)
ruby-htree 0.8%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 5,928; makefile: 23
file content (31 lines) | stat: -rw-r--r-- 597 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Regexp
  def disable_capture
    re = ''
    charclass_p = false
    self.source.scan(/\\.|[^\\\(\[\]]+|\(\?|\(|\[|\]/m) {|s|
      case s
      when '('
        if charclass_p
          re << '('
        else
          re << '(?:'
        end
      when '['
        charclass_p = true
        re << s
      when ']'
        charclass_p = false
        re << s
      else
        re << s
      end
    }
    if re.respond_to? :force_encoding
      re.force_encoding(self.encoding)
      Regexp.new(re, self.options)
    else
      Regexp.new(re, self.options, self.kcode)
    end
  end
end