File: byteoffset.rb

package info (click to toggle)
ruby-backports 3.25.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,759; makefile: 6
file content (12 lines) | stat: -rw-r--r-- 311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
unless MatchData.method_defined? :byteoffset
  class MatchData
    def byteoffset(n)
      if (char_start_offset = self.begin(n))
        char_end_offset = self.end(n)
        [string[0, char_start_offset].bytesize, string[0, char_end_offset].bytesize]
      else
        [nil, nil]
      end
    end
  end
end