Skip to content

Commit

Permalink
(imp) checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Jun 21, 2024
1 parent 92c60d2 commit 78ceb31
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}

- name: Checkstyle
run: ./gradlew checkstyleMain checkstyleTest

- name: Install PCRE
run: sudo apt-get install -y libpcre2-8-0

Expand Down
148 changes: 74 additions & 74 deletions PCRE2_API.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ the JNA.

### `ffm`

The `ffm` backend uses the [Foreign Functions and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html)
The `ffm` backend uses
the [Foreign Functions and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html)
to invoke the `pcre2` shared library. For this backend to work, the `pcre2` shared library must be installed on the
system and be visible via `java.library.path`.

Expand Down
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
plugins {
`java-library`
checkstyle
`maven-publish`
signing
jacoco
Expand Down
13 changes: 13 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.sourceforge.io/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="120"/>
<property name="ignorePattern"
value="^package.*|^import.*|href\s*=\s*&quot;[^&quot;]*&quot;|http://|https://|ftp://"/>
</module>
</module>
1 change: 1 addition & 0 deletions ffm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
plugins {
`java-library`
checkstyle
`maven-publish`
signing
jacoco
Expand Down
1 change: 1 addition & 0 deletions jna/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
plugins {
`java-library`
checkstyle
`maven-publish`
signing
jacoco
Expand Down
23 changes: 19 additions & 4 deletions jna/src/main/java/org/pcre4j/jna/Pcre2.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public Pcre2() {
/**
* Constructs a new PCRE2 API using the specified library name and function suffix.
*
* @param libraryName the library name
* (e.g. "pcre2-8" for "pcre2-8.dll" on Windows, "libpcre2-8.so" on Linux, "libpcre2-8.dylib" on macOS)
* @param libraryName the library name (e.g. "pcre2-8" for "pcre2-8.dll" on Windows, "libpcre2-8.so" on Linux,
* "libpcre2-8.dylib" on macOS)
* @param suffix the function suffix (e.g. "_8" as in "pcre2_compile_8")
*/
public Pcre2(String libraryName, String suffix) {
Expand Down Expand Up @@ -228,7 +228,14 @@ private interface Library extends com.sun.jna.Library {

void pcre2_compile_context_free(Pointer ccontext);

Pointer pcre2_compile(String pattern, long patternLength, int options, IntByReference errorcode, LongByReference erroroffset, Pointer ccontext);
Pointer pcre2_compile(
String pattern,
long patternLength,
int options,
IntByReference errorcode,
LongByReference erroroffset,
Pointer ccontext
);

void pcre2_code_free(Pointer code);

Expand All @@ -248,7 +255,15 @@ private interface Library extends com.sun.jna.Library {

void pcre2_match_context_free(Pointer mcontext);

int pcre2_match(Pointer code, String subject, long length, long startOffset, int options, Pointer matchData, Pointer mcontext);
int pcre2_match(
Pointer code,
String subject,
long length,
long startOffset,
int options,
Pointer matchData,
Pointer mcontext
);

int pcre2_get_ovector_count(Pointer matchData);

Expand Down
1 change: 1 addition & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
plugins {
`java-library`
checkstyle
`maven-publish`
signing
jacoco
Expand Down
44 changes: 22 additions & 22 deletions lib/src/main/java/org/pcre4j/Pcre2CompileError.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ public Pcre2CompileError(String pattern, long offset, String message, Throwable
this.message = message;
}

/**
* Get the region around the error in the pattern.
*
* @param pattern the pattern
* @param offset the offset of the error in the pattern
* @return the region around the error
*/
private static String getPatternRegion(String pattern, long offset) {
final var since = Math.max(0, offset - PATTERN_REGION_SIZE);
final var until = Math.min(pattern.length(), offset + PATTERN_REGION_SIZE);

var region = pattern.substring((int) since, (int) until);
if (since > 0) {
region = "…" + region;
}
if (until < pattern.length()) {
region = region + "…";
}

return region;
}

/**
* Get the pattern that caused the error.
*
Expand Down Expand Up @@ -89,26 +111,4 @@ public String message() {
return message;
}

/**
* Get the region around the error in the pattern.
*
* @param pattern the pattern
* @param offset the offset of the error in the pattern
* @return the region around the error
*/
private static String getPatternRegion(String pattern, long offset) {
final var since = Math.max(0, offset - PATTERN_REGION_SIZE);
final var until = Math.min(pattern.length(), offset + PATTERN_REGION_SIZE);

var region = pattern.substring((int) since, (int) until);
if (since > 0) {
region = "…" + region;
}
if (until < pattern.length()) {
region = region + "…";
}

return region;
}

}
1 change: 1 addition & 0 deletions regex/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
plugins {
`java-library`
checkstyle
`maven-publish`
signing
jacoco
Expand Down
2 changes: 0 additions & 2 deletions regex/src/main/java/org/pcre4j/regex/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

import org.pcre4j.Pcre2MatchData;
import org.pcre4j.Pcre2MatchOption;
import org.pcre4j.Pcre4j;
import org.pcre4j.Pcre4jUtils;
import org.pcre4j.api.IPcre2;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.Map;
import java.util.regex.MatchResult;

/**
* Performs match operations on a character sequence by interpreting a {@link Pattern} using the PCRE library yet aims
Expand Down
4 changes: 2 additions & 2 deletions regex/src/main/java/org/pcre4j/regex/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public String[] splitWithDelimiters(CharSequence input, int limit) {
* Splits the given input around matches of this pattern and returns either just the strings or both the strings
* and the matching delimiters.
*
* @param input the input to split
* @param limit the maximum number of items to return
* @param input the input to split
* @param limit the maximum number of items to return
* @param includeDelimiters whether to include the matching delimiters in the result
* @return the array of strings and optionally matching delimiters computed by splitting the input around matches
* of this pattern
Expand Down
1 change: 1 addition & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
plugins {
`java-library`
checkstyle
jacoco
}

Expand Down

0 comments on commit 78ceb31

Please sign in to comment.