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

Class UTF16Input

java/com/google/re2j/MachineInput.java:174–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172
173 // |pos| and |width| are in Java "char" units.
174 private static class UTF16Input extends MachineInput {
175 final CharSequence str;
176 final int start;
177 final int end;
178
179 public UTF16Input(CharSequence str, int start, int end) {
180 this.str = str;
181 this.start = start;
182 this.end = end;
183 }
184
185 @Override
186 int step(int pos) {
187 pos += start;
188 if (pos < end) {
189 int rune = Character.codePointAt(str, pos);
190 return rune << 3 | Character.charCount(rune);
191 } else {
192 return EOF;
193 }
194 }
195
196 @Override
197 boolean canCheckPrefix() {
198 return true;
199 }
200
201 @Override
202 int index(RE2 re2, int pos) {
203 pos += start;
204 int i = indexOf(str, re2.prefix, pos);
205 return i < 0 ? i : i - pos;
206 }
207
208 @Override
209 int context(int pos) {
210 pos += start;
211 int r1 = pos > 0 && pos <= str.length() ? Character.codePointBefore(str, pos) : -1;
212 int r2 = pos < str.length() ? Character.codePointAt(str, pos) : -1;
213 return Utils.emptyOpContext(r1, r2);
214 }
215
216 @Override
217 int endPos() {
218 return end;
219 }
220
221 private int indexOf(CharSequence hayStack, String needle, int pos) {
222 if (hayStack instanceof String) {
223 return ((String) hayStack).indexOf(needle, pos);
224 }
225 if (hayStack instanceof StringBuilder) {
226 return ((StringBuilder) hayStack).indexOf(needle, pos);
227 }
228 return indexOfFallback(hayStack, needle, pos);
229 }
230
231 // Modified version of {@link String#indexOf(String) that allows a CharSequence.

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…