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

Class MatcherInput

java/com/google/re2j/MatcherInput.java:14–105  ·  view source on GitHub ↗

Abstract the representations of input text supplied to Matcher.

Source from the content-addressed store, hash-verified

12 * Abstract the representations of input text supplied to Matcher.
13 */
14abstract class MatcherInput {
15
16 enum Encoding {
17 UTF_16,
18 UTF_8,
19 }
20
21 /**
22 * Return the MatcherInput for UTF_16 encoding.
23 */
24 static MatcherInput utf16(CharSequence charSequence) {
25 return new Utf16MatcherInput(charSequence);
26 }
27
28 /**
29 * Return the MatcherInput for UTF_8 encoding.
30 */
31 static MatcherInput utf8(byte[] bytes) {
32 return new Utf8MatcherInput(bytes);
33 }
34
35 /**
36 * Return the MatcherInput for UTF_8 encoding.
37 */
38 static MatcherInput utf8(String input) {
39 return new Utf8MatcherInput(input.getBytes(Charset.forName("UTF-8")));
40 }
41
42 abstract Encoding getEncoding();
43
44 abstract CharSequence asCharSequence();
45
46 abstract byte[] asBytes();
47
48 abstract int length();
49
50 static class Utf8MatcherInput extends MatcherInput {
51 byte[] bytes;
52
53 public Utf8MatcherInput(byte[] bytes) {
54 this.bytes = bytes;
55 }
56
57 @Override
58 public Encoding getEncoding() {
59 return Encoding.UTF_8;
60 }
61
62 @Override
63 public CharSequence asCharSequence() {
64 return new String(bytes, Charset.forName("UTF-8"));
65 }
66
67 @Override
68 public byte[] asBytes() {
69 return bytes;
70 }
71

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…