Package org.jline.utils
Class SafeRegex.TimeoutCharSequence
java.lang.Object
org.jline.utils.SafeRegex.TimeoutCharSequence
- All Implemented Interfaces:
CharSequence
- Enclosing class:
SafeRegex
A
CharSequence wrapper that enforces a wall-clock deadline.
The Java regex engine calls charAt(int) for every position
it considers during matching. During catastrophic backtracking the
call count explodes; we check System.nanoTime() every
1024 calls and throw if the deadline has passed.
The deadline is lazily initialised on the first charAt
check so the timeout measures actual matching time, not the gap
between Matcher creation and first use. Instances created
via subSequence(int, int) share the same deadline array, so the
timeout covers the entire matching operation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final CharSequenceprivate final long[]Shared acrosssubSequence(int, int)calls; element 0 holds the deadline (0 = not yet started).private final long -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)TimeoutCharSequence(CharSequence inner, long timeoutNanos) privateTimeoutCharSequence(CharSequence inner, long timeoutNanos, long[] sharedDeadline) -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) intlength()subSequence(int start, int end) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
inner
-
timeoutNanos
private final long timeoutNanos -
calls
private int calls
-
-
Constructor Details
-
TimeoutCharSequence
TimeoutCharSequence(CharSequence inner, long timeoutNanos) -
TimeoutCharSequence
-
-
Method Details
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-