forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.util.regex.rb
More file actions
83 lines (67 loc) · 1.13 KB
/
java.util.regex.rb
File metadata and controls
83 lines (67 loc) · 1.13 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class java::util::regex::Pattern
def =~(str)
m = self.matcher(str)
m.find ? m.start : nil
end
def ===(str)
self.matcher(str).find
end
def match(str)
m = self.matcher(str)
m.str = str
m.find ? m : nil
end
end
class java::util::regex::Matcher
attr_accessor :str
def captures
g = self.group_count
capt = []
count.times do |i|
capt << self.group(i+1)
end
capt
end
def [](*args)
self.to_a[*args]
end
def begin(ix)
self.start(ix)
end
def end(ix)
self.java_send(:end, [Java::int], ix)
end
def to_a
arr = []
self.group_count.times do |gg|
if self.start(gg) == -1
arr << nil
else
arr << self.group(gg)
end
end
arr
end
def size
self.group_count
end
alias length size
def values_at(*args)
self.to_a.values_at(*args)
end
def select
yield self.to_a
end
def offset(ix)
[self.start(ix), self.end(ix)]
end
def pre_match
self.str[0..(self.start(0))]
end
def post_match
self.str[(self.end(0))..-1]
end
def string
self.group(0)
end
end