Skip to content

Commit

Permalink
(imp) lib: Pcre2CompileError to retain properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Jun 20, 2024
1 parent e70bc3e commit aeeecc9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/src/main/java/org/pcre4j/Pcre2CompileError.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ public class Pcre2CompileError extends IllegalArgumentException {
*/
private static final int PATTERN_REGION_SIZE = 3;

/**
* The pattern that caused the error
*/
private final String pattern;

/**
* The offset of the error in the pattern
*/
private final long offset;

/**
* The error message
*/
private final String message;

/**
* Create a new pattern compilation error.
*
Expand All @@ -42,6 +57,36 @@ public Pcre2CompileError(String pattern, long offset, String message) {
*/
public Pcre2CompileError(String pattern, long offset, String message, Throwable cause) {
super("Error in pattern at %d (%s): %s".formatted(offset, getPatternRegion(pattern, offset), message), cause);
this.pattern = pattern;
this.offset = offset;
this.message = message;
}

/**
* Get the pattern that caused the error.
*
* @return the pattern
*/
public String pattern() {
return pattern;
}

/**
* Get the offset of the error in the pattern.
*
* @return the offset
*/
public long offset() {
return offset;
}

/**
* Get the error message.
*
* @return the error message
*/
public String message() {
return message;
}

/**
Expand Down

0 comments on commit aeeecc9

Please sign in to comment.