blob: aa42f812d28b793f763c856b12ac5543f84ce9c8 (
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// Copyright Yahoo. 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.Optional;
import java.util.function.Function;
import java.util.regex.Pattern;
/**
* Simulates an editor cursor.
*
* @author hakon
*/
public interface Cursor {
// CURSOR AND BUFFER QUERIES
String getBufferText();
String getLine();
String getPrefix();
String getSuffix();
String getTextTo(Mark mark);
Position getPosition();
Mark createMark();
// CURSOR MOVEMENT
Cursor moveToStartOfBuffer();
Cursor moveToEndOfBuffer();
Cursor moveToStartOfLine();
Cursor moveToStartOfPreviousLine();
Cursor moveToStartOfNextLine();
Cursor moveToStartOf(int lineIndex);
Cursor moveToEndOfLine();
Cursor moveToEndOfPreviousLine();
Cursor moveToEndOfNextLine();
Cursor moveToEndOf(int lineIndex);
Cursor moveForward();
Cursor moveForward(int times);
Cursor moveBackward();
Cursor moveBackward(int times);
Cursor moveTo(Mark mark);
Cursor moveTo(Position position);
Cursor moveTo(int lineIndex, int columnIndex);
Optional<Match> moveForwardToStartOfMatch(Pattern pattern);
Optional<Match> moveForwardToEndOfMatch(Pattern pattern);
boolean skipBackward(String text);
boolean skipForward(String text);
// BUFFER MODIFICATIONS
Cursor write(String text);
Cursor writeLine(String line);
Cursor writeLines(String... lines);
Cursor writeLines(Iterable<String> lines);
Cursor writeNewline();
Cursor writeNewlineAfter();
Cursor deleteAll();
Cursor deleteLine();
Cursor deletePrefix();
Cursor deleteSuffix();
Cursor deleteForward();
Cursor deleteForward(int times);
Cursor deleteBackward();
Cursor deleteBackward(int times);
Cursor deleteTo(Mark mark);
boolean replaceMatch(Pattern pattern, Function<Match, String> replacer);
/**
* Replace matches of a pattern.
*
* <p>The search for {@code pattern} starts at cursor and matches against the remaining line,
* and the full line for the following lines. Each match is replaced by a String returned by
* {@code replacer::apply}.
*
* <p>The cursor is unchanged without any matches, or moved to the end of the last replacement.
*
* <p>To replace all matches in a buffer, first call {@link #moveToStartOfBuffer()} to
* postion the cursor at the beginning of the buffer.
*
* @see #moveForwardToStartOfMatch(Pattern)
* @see #moveForwardToEndOfMatch(Pattern)
*/
int replaceMatches(Pattern pattern, Function<Match, String> replacer);
}
|