blob: 32e058c10670a4bdec9ecade5e7fd91bfc16cf68 (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.editor;
import java.util.regex.Matcher;
/**
* Represents a pattern match of a line
*
* @author hakon
*/
public class Match {
private final int lineIndex;
private final String line;
private final Matcher matcher;
Match(int lineIndex, String line, Matcher matcher) {
this.lineIndex = lineIndex;
this.line = line;
this.matcher = matcher;
}
/** The part of the line before the match */
public String prefix() {
return line.substring(0, matcher.start());
}
/** The part of the line that matched */
public String match() {
return matcher.group();
}
/** The part of the line that followed the match */
public String suffix() {
return line.substring(matcher.end());
}
public Position startOfMatch() {
return new Position(lineIndex, matcher.start());
}
public Position endOfMatch() {
return new Position(lineIndex, matcher.end());
}
public int groupCount() {
return matcher.groupCount();
}
public String group(int groupnr) {
return matcher.group(groupnr);
}
}
|