MCPcopy Create free account
hub / github.com/google/re2j / MachineInput

Class MachineInput

java/com/google/re2j/MachineInput.java:16–267  ·  view source on GitHub ↗

MachineInput abstracts different representations of the input text supplied to the Machine. It provides one-character lookahead.

Source from the content-addressed store, hash-verified

14 * provides one-character lookahead.
15 */
16abstract class MachineInput {
17
18 static final int EOF = (-1 << 3);
19
20 static MachineInput fromUTF8(byte[] b) {
21 return new UTF8Input(b);
22 }
23
24 static MachineInput fromUTF8(byte[] b, int start, int end) {
25 return new UTF8Input(b, start, end);
26 }
27
28 static MachineInput fromUTF16(CharSequence s) {
29 return new UTF16Input(s, 0, s.length());
30 }
31
32 static MachineInput fromUTF16(CharSequence s, int start, int end) {
33 return new UTF16Input(s, start, end);
34 }
35
36 //// Interface
37
38 // Returns the rune at the specified index; the units are
39 // unspecified, but could be UTF-8 byte, UTF-16 char, or rune
40 // indices. Returns the width (in the same units) of the rune in
41 // the lower 3 bits, and the rune (Unicode code point) in the high
42 // bits. Never negative, except for EOF which is represented as -1
43 // << 3 | 0.
44 abstract int step(int pos);
45
46 // can we look ahead without losing info?
47 abstract boolean canCheckPrefix();
48
49 // Returns the index relative to |pos| at which |re2.prefix| is found
50 // in this input stream, or a negative value if not found.
51 abstract int index(RE2 re2, int pos);
52
53 // Returns a bitmask of EMPTY_* flags.
54 abstract int context(int pos);
55
56 // Returns the end position in the same units as step().
57 abstract int endPos();
58
59 //// Implementations
60
61 // An implementation of MachineInput for UTF-8 byte arrays.
62 // |pos| and |width| are byte indices.
63 private static class UTF8Input extends MachineInput {
64
65 final byte[] b;
66 final int start;
67 final int end;
68
69 UTF8Input(byte[] b) {
70 this.b = b;
71 start = 0;
72 end = b.length;
73 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…