MCPcopy Create free account
hub / github.com/ReadyTalk/avian / isPlainString

Method isPlainString

classpath/java/util/regex/PikeVM.java:471–494  ·  view source on GitHub ↗

Determines whether this machine recognizes a pattern without special operators. In case that the regular expression is actually a plain string without any special operators, we can avoid using a full-blown Pike VM and instead fall back to using the much faster TrivialPattern. @retu

()

Source from the content-addressed store, hash-verified

469 * non-trivial pattern
470 */
471 public String isPlainString() {
472 // we expect the machine to start with the find preamble and SAVE_OFFSET 0
473 // end with SAVE_OFFSET 1
474 int start = findPrefixLength;
475 if (start + 1 < program.length &&
476 program[start] == SAVE_OFFSET && program[start + 1] == 0) {
477 start += 2;
478 }
479 int end = program.length;
480 if (end > start + 1 &&
481 program[end - 2] == SAVE_OFFSET && program[end - 1] == 1) {
482 end -= 2;
483 }
484 for (int i = start; i < end; ++ i) {
485 if (program[i] < 0) {
486 return null;
487 }
488 }
489 char[] array = new char[end - start];
490 for (int i = start; i < end; ++ i) {
491 array[i - start] = (char)program[i];
492 }
493 return new String(array);
494 }
495
496 private static int length(int opcode) {
497 return opcode <= SINGLE_ARG_START && opcode >= SINGLE_ARG_END ? 2 : 1;

Callers 1

compileMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected