Skip to content

Commit

Permalink
Merge pull request #527 from blazegraph/BLZG-8999
Browse files Browse the repository at this point in the history
Blzg 8999
  • Loading branch information
beebs-systap authored Mar 8, 2019
2 parents 8471533 + d13f320 commit 3def261
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.bigdata.rdf.internal.constraints;
/**
* CharSequence that noticed thread interrupts -- as might be necessary
* to recover from a loose regex on unexpected challenging input.
* From: https://stackoverflow.com/a/910798/214196
* @author gojomo
*/
public class InterruptibleCharSequence implements CharSequence {
/**
* Parent sequence.
*/
private final CharSequence inner;

public InterruptibleCharSequence(CharSequence inner) {
this.inner = inner;
}

@Override
public char charAt(int index) {
if (Thread.interrupted()) { // clears flag if set
throw new RuntimeException(new InterruptedException());
}
return inner.charAt(index);
}

@Override
public int length() {
return inner.length();
}

@Override
public CharSequence subSequence(int start, int end) {
return new InterruptibleCharSequence(inner.subSequence(start, end));
}

@Override
public String toString() {
return inner.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private boolean accept(final Value arg, final Value parg, final Value farg) {

}

final boolean result = pattern.matcher(text).find();
final boolean result = pattern.matcher(new InterruptibleCharSequence(text)).find();

return result;

Expand Down

0 comments on commit 3def261

Please sign in to comment.